This content has been marked as final.
Show 3 replies
-
1. Re: Using a JoinTable, getting unique constraint violtions
smokingapipe Feb 14, 2007 5:27 PM (in response to smokingapipe)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? -
2. Re: Using a JoinTable, getting unique constraint violtions
smokingapipe Feb 14, 2007 6:11 PM (in response to smokingapipe)I ended up creating a placeholder entity. If that's the only way to do this, that's an unfortunate defect in the EJB3 spec. If there is some way please let me know.
-
3. Re: Using a JoinTable, getting unique constraint violtions
fhh Feb 16, 2007 5:24 AM (in response to smokingapipe)This is not a one-to-many relationship but a (unidirectional) many-to-many. (One product belongs to many invoices, many invoices belong to one one product).
Regards
Felix