Question

Hello i want to add a unique constraint over two referenced columns:

@Entity()
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "ast", "tfs" }))
public class N extends UUID {

@ManyToOne(optional = false)
@JoinColumn(name = "ast")
private A ast;

@ManyToOne(optional = false)
@JoinColumn(name = "tfs")
private T tfs;

In Class UUID is logic for generating a Primary ID.

Hibernate generates 3 Constraint, PK, 2 Secondary Keys.. but i am expecting 4 Constraints. Does someone have a idea ?

Edit:

@Entity
public class A extends UUID implements Serializable {

@OneToMany(mappedBy = "ast")
private List<N> nutz;

and

@Entity
public class T extends UUID implements Serializable {

@OneToMany(mappedBy = "tfs")
private List<N> nutz;
Was it helpful?

Solution

It works if I set:

<property name="hibernate.hbm2ddl.auto" value="create-drop" />

instead of

<property name="hibernate.hbm2ddl.auto" value="update" />

It seems Hibernate only creates constaints if the whole database is created and not when it creates the table! Confusing. related

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top