Hibernate: @UniqueConstraint with @ManyToOne field???
Posted
by Misha Koshelev
on Stack Overflow
See other posts from Stack Overflow
or by Misha Koshelev
Published on 2010-06-18T04:29:12Z
Indexed on
2010/06/18
4:33 UTC
Read the original article
Hit count: 402
Dear All:
Using the following code:
@Entity
@Table(uniqueConstraints=[@UniqueConstraint(columnNames=["account","name"])])
class Friend {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long id
@ManyToOne
public Account account
public String href
public String name
}
I get the following error:
org.hibernate.AnnotationException: Unable to create unique key constraint (account, name) on table Friend: account not found
It seems this has to do with the @ManyToOne constraint, which I imagine actually creates a separate UniqueConstraint???
In any case, if I take this out, there is no complaint about the UniqueConstraint, but there is another error which makes me believe it must be left in.
org.hibernate.MappingException: Could not determine type for: com.mksoft.fbautomate.domain.Account, at table: Friend, for columns: [org.hibernate.mapping.Column(account)]
Any hints how I can create such a desired constraint (i.e., that each combination of account and name occurs only once???)
Thank you!
Misha
© Stack Overflow or respective owner