Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Thorny JPA @OneToMany + @Generated + @EmbeddedId question

On Thu, May 28, 2009 at 1:44 PM, Tom Ware <tom.ware@xxxxxxxxxx> wrote:
 JPA 2.0 should cover the case you are looking at.  It adds a feature called Derived Identifiers that supports having the id as part of a relationship.

Thanks, Tom.  Will this handle the case where the dependent object (the Address) has part of its multipart ID pointing to the generated serial PK of its parent (the Person)?  That, to me, is the real issue. 

That is, if I create an in-memory graph of a Person and an Address, then, before persisting, I have:
  • A Person whose ID hasn't been set yet (since it's generated by the database), and whose Address collection contains the Address
  • The Address so contained, whose type (1/2 of its PK) is set, and whose person property is set (to the Person described in the first bullet point), but recall that this Person does not yet have his serial ID set, since he hasn't been persisted yet
When I persist this graph by calling entityManager.persist(person) (with cascading, obviously), is a JPA 2.0 implementation such as EclipseLink smart enough to realize that it has to:
  • insert the Person first and "remember" the generated ID that the database came up with
  • make sure that the Address's reference to that Person now refers to the "identified" Person
  • insert the Address last
...?

Thanks for your input,
Laird

Back to the top