[jboss-user] [EJB 3.0] - Re: Using a JoinTable, getting unique constraint violtions

SmokingAPipe do-not-reply at jboss.com
Wed Feb 14 17:27:32 EST 2007


I figured out the problem, but not the solution.

Here's the problem:

I have a uni-directional Collection in my Invoice:

@Entity class Invoice {
  | 
  |    @OneToMany Collection<Product> getProducts();
  | 
  | }

This results in creating a join table, with a unique constraint on the product_id column, which doesn't work because the Collection can have the same Product multiple times.

The naive solution would be a table that looks like:

invoice_id    product_id
  | 33                   88
  | 33                   88

But that's not a proper relation.  Rows (tuples) must be unique.

What is needed is a third column, which is a row ID.  I can't see anything in the docs about how I could do that.  Any suggestions?


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

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



More information about the jboss-user mailing list