In a Java class, I have this property
@OneToOne(optional = false, fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private MyPropertyClass myProperty;
which not only creates a foreign key constraint, but a unique constraint also. This is the Hibernate DDL Schema output:
Hibernate: create table [...]
Hibernate: alter table [...] add constraint UK_nk1hqjkd7ln1f9a2pju1yy8ay unique (myProperty)
Is there any way to specify the name of the unique constraint?
Please try uniqueConstraints
attribute of @Table
annotation in the class level.
@Table( name ="tablename " , uniqueConstraints={
@UniqueConstraint(name="myconst", columnNames={"myProp"})
})
public class MyEntity {
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name="myProp")
private MyPropertyClass myProperty;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With