0

I have a class called Iteraction this iteration have many fields in special i want do a validation of uniqueness for three fields together (startDate, endDate and Project), Project is a class.

I try do something like that:

@Table(uniqueConstraints = {@UniqueConstraint(columnNames={"startDate", "endDate", "project_id"})})

But dont work, what a want say to my validation is: i can only have ONE register of iteration in database with the same startDade, endDate and project_id:

In Rails Code i can use Scope for that, but using hibernate i don't know how, can someone help me?

Édipo Féderle
  • 4,169
  • 5
  • 31
  • 35

1 Answers1

1

A quick look to the documentations shows that the syntax is a bit different:

@Table(name="whatever", uniqueConstraints=@Unique(columnNames={"startDate","endDate", "project_id"))

Hope that helps.

One more answer was at unique constraint check in JPA — check it out.

Community
  • 1
  • 1
alf
  • 8,377
  • 24
  • 45