Hibernate - unique column constraint being ignored

前端 未结 2 593
暗喜
暗喜 2021-01-18 10:22

I have a MySQL table to hold tags (i.e. like those used here on Stack Overflow). It simply has an id (pk) and a tag column to hold the tag itself.

The annotated get

相关标签:
2条回答
  • 2021-01-18 10:52

    From JavaDoc of UniqueConstraint (unique=true on @Colunm is just a shortcut):

    This annotation is used to specify that a unique constraint is to be included in the generated DDL for a primary or secondary table.

    So it does not seem to enforce uniqueness upon inserts. You should create a unique constraint in the database in any case.

    0 讨论(0)
  • 2021-01-18 10:54

    You miss that this is only a information.

    You should add also constraint on the column in database.

    0 讨论(0)
提交回复
热议问题