0

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;
Matthias H
  • 1,300
  • 13
  • 19
  • I would expect in your case only two constraints: the PK constraint and the UniqueConstraint (over two fields). What are the constraints of Hibernate and what are the constraints that you expect? – V G Nov 25 '13 at 13:51
  • Then i have no reference to the other entitys. At the moment there are 1PrimaryKey(uuid) 2SecondaryKey(to ast and to tfs) Constraints. I expect 1PrimaryKey 2SecondaryKey plus 1Uniqe(ast,tfs) constraint. – Matthias H Nov 25 '13 at 13:55
  • Of course, I didn't count the Foreign Key constraints. Are you sure you do not have multiple combinations `{"ast", "tfs"}` in your table? – V G Nov 25 '13 at 14:00

1 Answers1

1

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

Community
  • 1
  • 1
Matthias H
  • 1,300
  • 13
  • 19