[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Thorny JPA @OneToMany + @Generated + @EmbeddedId question
|
Hi Laird,
The scenario you suggest below should work with one caveat:
Whe you say, "make sure that the Address's reference to that Person now
refers to the "identified" Person", it kind of depends what you are saying. In
JPA, you are responsible for ensuring all the object references are correct
prior to doing a flush or commit (make sure Person's collection of Address
contains your address and the backpointer from Address to Person is properly
set). If you have done that, JPA should take care of the keys in the database.
-Tom
Laird Nelson wrote:
On Thu, May 28, 2009 at 1:44 PM, Tom Ware <tom.ware@xxxxxxxxxx
<mailto: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
------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users