Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » retrieving the assigned primary key
retrieving the assigned primary key [message #489625] Mon, 05 October 2009 07:58 Go to next message
Eclipse UserFriend
I've moved a piece of code to native queries because of locking and conflicts with Eclipselinks' cache. But on the boundary between Eclipselink and native I need to be able to access the primary keys that Eclipselink assigned to newly inserted entities. In this specific scenario it's the PK of an entity that is persisted by reference in a 1-N relation. Is there any way to find the PK that is assigned to a entity immediately after the pk was created from the sequence table?

The other approach would be for me to set that primary key myself. That I will test now.

Tom
Re: retrieving the assigned primary key [message #489649 is a reply to message #489625] Mon, 05 October 2009 09:35 Go to previous messageGo to next message
Eclipse UserFriend
You can access the assigned Id from your object after calling persist() (or flush() if using IDENTITY).

You could also use the PostPersist event.
Re: retrieving the assigned primary key [message #489692 is a reply to message #489649] Mon, 05 October 2009 10:59 Go to previous messageGo to next message
Eclipse UserFriend
James wrote:
> You can access the assigned Id from your object after calling persist()
> (or flush() if using IDENTITY).
>
> You could also use the PostPersist event.

I assumed that too, but I never call persist myself. Setting it myself works fine, but I wonder where the automatically assigned PK went.
Re: retrieving the assigned primary key [message #491695 is a reply to message #489692] Thu, 15 October 2009 09:50 Go to previous messageGo to next message
Eclipse UserFriend
Hi all,

I have a question similar to this. I

I wouuld retrive the assigned primary key for an entity that I have
persisted but it has been persisted because insede a relationship.

I mean, I have two entity A and B. A has a list of B entities.
I add a B entity in the A list entity then I persist the A Entity
(cascade all). So, the new persisted entity is an B entity. I would
retrieve immediately the primary key of the B entity, but it seems that
after persist and also flush the B entity object has not acquired the
rimary key.
Obviously I can try using a findbyexample after persisting the A entity,
but I prefer to have the primary key on the B object after persist.

Best Regards,
Enrico

tbee ha scritto:
> James wrote:
>> You can access the assigned Id from your object after calling
>> persist() (or flush() if using IDENTITY).
>>
>> You could also use the PostPersist event.
>
> I assumed that too, but I never call persist myself. Setting it myself
> works fine, but I wonder where the automatically assigned PK went.
>
Re: retrieving the assigned primary key [message #491696 is a reply to message #491695] Thu, 15 October 2009 09:53 Go to previous messageGo to next message
Eclipse UserFriend
For me the set-primary-key-myself worked fine, but indeed indirectly persisted entities did not receive a PK.

Tom
Re: retrieving the assigned primary key [message #492215 is a reply to message #491696] Mon, 19 October 2009 09:48 Go to previous message
Eclipse UserFriend
Objects persisted through cascade persist will still have an Id assigned. If using IDENTITY you must call flush().

If you are not noticing the Id assigned, then what is being inserted into the database on flush or commit?

Are you should your relationship is cascade persist, also check to ensure you don't have multiple copies of the same object registered.

Previous Topic:EMF/Teneo and EclipseLink integration
Next Topic:Random deadlock/hang during commit in EJB3 application
Goto Forum:
  


Current Time: Thu Jul 03 13:09:12 EDT 2025

Powered by FUDForum. Page generated in 0.03133 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top