1

I apologize if I repeat the question, but I did not find a similar one.

I have added a unique constraint on an already existent table. We use MariaDB.

I have used the annotation:

@Table(uniqueConstraints={@UniqueConstraint(name="autonomy_name_energyType", columnNames={"autonomy","name","energyType"})})

The unit tests pass, but in the DB I am still allowed to create duplicates.

Do I need an ALTER table too? By checking the table I can see there are no constraints added to it.

Thanks

1 Answers1

0

As explained in these SO posts :

An explicit alter table query is needed for ur constaints to take effect on the db level.

As an extra info, it would have worked if the table was being re-created via JPA. see : Add a unique constraint over muliple reference columns

Orkun
  • 6,998
  • 8
  • 56
  • 103