[jboss-user] [EJB 3.0] - Re: How to define unique constraint on foreign keys ?

chawax do-not-reply at jboss.com
Mon Oct 15 03:21:28 EDT 2007


Thanks. But what I need is a unique constraint on multiple columns, including columns that are foreign keys.

Anyway, I solved my problem by using the attribute "name" of the JoinColumn annotation instead of the property name. 

@javax.persistence.Table(
  | 		name = "UNITE_EMPLOYE",
  | 		uniqueConstraints = {
  | 				@javax.persistence.UniqueConstraint(columnNames = {"EMPLOYE_FK", "NOEUD_ORGANISATION_FK"})})
  | 

What is strange is that in the Hibernate documentation, it is said :

anonymous wrote : The @Table element also contains a schema and a catalog attributes, if they need to be defined. You can also define unique constraints to the table using the @UniqueConstraint annotation in conjunction with @Table (for a unique constraint bound to a single column, refer to @Column).
  | 
  | @Table(name="tbl_sky",
  | uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})}
  | )
  | 
  | A unique constraint is applied to the tuple month, day. Note that the columnNames array refers to the logical column names.

Am I wrong when I think that logical column name is the property name of the entity bean ? Or maybe there's a difference between Hibernate and EJB3 entities about this ?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095104#4095104

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095104



More information about the jboss-user mailing list