Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » How to access Primary Key instance of entity relationship?
How to access Primary Key instance of entity relationship? [message #1064468] Wed, 19 June 2013 08:23 Go to next message
Eclipse UserFriend
I want to turn entity instances into XML representations using JAXB. For LAZY references, I want to simply contain a URL (made up of the referenced Primary key), so that each XML receiver can decide on his own whether to explicitly load this extra information or not. So I wrote an XmlAdapter to turn relationships into URLs, which works well, but has the drawback, that as soon as I access the LAZY relationship to find out the primary key, certainly it is loaded by the entity manager. This is not nice, as I do not need all this data -- but solely the primary key.

So I wonder whether there is a way to get the primary key of a referenced entity without actually loading its complete state into memory?
Re: How to access Primary Key instance of entity relationship? [message #1065390 is a reply to message #1064468] Tue, 25 June 2013 10:26 Go to previous messageGo to next message
Eclipse UserFriend
Please log a bug to have a helper API added for this.

If you also map the foreign key as a @Basic (you can mark it insertable/updateable=false), then you can access the id.

You could also use,

AbstractSession session = (AbstractSession)em.unwrap(Session.class);
OneToOneMapping mapping = session .getDescriptor(entity.getClass()).getObjectBuilder().getMappingForAttributeName(attribute);
Object id = mapping.valueFromObject(entity, mapping.getForeignKeyFields().get(0), session);

Re: How to access Primary Key instance of entity relationship? [message #1065392 is a reply to message #1065390] Tue, 25 June 2013 10:27 Go to previous message
Eclipse UserFriend
Another option is to encode the root object id and the attribute name. Then you just load the root object, and access the attribute when the url is accessed. This will also work for collection relationships, so is probably better.
Previous Topic:How to use eclipselink.batch with em.find()?
Next Topic:entitymanager problem merge
Goto Forum:
  


Current Time: Thu Jul 10 03:02:40 EDT 2025

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

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

Back to the top