Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Cascade persist and map keys
Cascade persist and map keys [message #661994] Mon, 28 March 2011 15:30 Go to next message
Dave M is currently offline Dave M
Messages: 20
Registered: July 2009
Junior Member
Given the following entities::

public class ContainingEntity
{
    private Long oid; //pk
    private Map<MapKeyEntity, MapValueEntity> valuesByKey;
}

public class MapKeyEntity
{
    private Long oid; //pk
}

public class MapValueEntity
{
    private Long oid; //pk
}


and assuming the mapping for ContainingEntity.valuesByKey (in orm.xml terms) is something like:

<one-to-many name="valuesByKey">
    <map-key-join-column name="MAP_KEY_ID" />
    <join-table name="MAP_VALUES_BY_KEY">
        <join-column name="CONTAINER_ID" />
        <inverse-join-column name="MAP_VALUE_ID" />
    </join-table>
    <cascade><cascade-persist /></cascade>
</one-to-many>


Let's say we create one new instance of ContainingEntity and add one entry to its valuesByKey map, where the key is a new instance of MapKeyEntity and the value is a new instance of MapValueEntity (where "new" means not yet persistent);

Finally, let's say we call "entityManager.persist(aContainingEntity)" passing in the little graph of 3 new objects.

Should I expect the "cascade persist" instruction to cause EclipseLink to find and persist the instance of MapKeyEntity? Or does the MapKeyEntity need to be (or have been) persisted some other way?

Thanks,

Dave
Re: Cascade persist and map keys [message #662676 is a reply to message #661994] Thu, 31 March 2011 10:10 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I think the cascade options only apply to the value not the key of the Map. So, you are better off to persist the key.

I'm not exactly certain what will occur if you don't, please try it and confirm.

It would be possible in EclipseLink to use a DescriptorCustomizer to access the OneToOneMapping for the MapKeyContainerPolicy and enable cascading on it directly. But I don't think JPA has any way to configure this through annotations or xml.


James : Wiki : Book : Blog : Twitter
Previous Topic:Surrogate auto-generated VS natural primary keys with JPA
Next Topic:JAP and RCP javax.persistence.PersistenceException: No Persistence provider for EntityManager named
Goto Forum:
  


Current Time: Sat Jul 26 01:21:11 EDT 2014

Powered by FUDForum. Page generated in 0.23315 seconds