My use case is as follows: I use MySQL and JPA 2 and I have two entities: Order and LineItem that are associated by a OneToMany relationship.
I would like for the GUI layer to persist the Order together with the LineItems at the same time (using the Order PK).
Bearing in mind that the PK of Order is auto-generated by MySQL and is part of the PK of LineItem, I don't know how to retrieve the generated Order PK in order to use it for the LineItem PK within the same transaction.
Is there any special JPA configuration I could use to achieve this?
I am actually realizing that my domain is a bit more complicated that what I described initially.
My domain is as follows: I have an Advertisement entity engaged in a many to many relationship with a TimeSlot entity with a join entity sitting in between the two entities: AdvertisementToTimeSlotToDayJoin. There is actually a third entity Day which I have omitted.
The only value that is not know in advance, as far as the constructor of AdvertisementToTimeSlotToDayJoinPK is concerned is the Avertisement PK, wich is autogenerated. How then can I persist my Avertisement together with its related join entities?
Exception Description: The @JoinColumns on the annotated element [field advertisementToTimeSlotToDayJoinCollection] from the entity class [class com.bignibou.domain.Advertisement] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss