Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » cannotAddElementWithoutKeyToMap(Map with entities for key and value)
cannotAddElementWithoutKeyToMap [message #542557] Fri, 25 June 2010 10:35 Go to next message
Guy is currently offline GuyFriend
Messages: 3
Registered: June 2010
Junior Member
I have an entity containing a Map for which the key and value are both entities:

@OneToMany(cascade = ALL, orphanRemoval = true)
name = "countryprice_price",
joinColumns = @JoinColumn(name = "countryprice_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "price_id", referencedColumnName = "id"))
@MapKeyJoinColumn(name = "country_id", referencedColumnName = "id")
public Map<Country, Price> getPrices() {
return prices;

When creating a new country, a new price is created for this country and added to the above entity (CountryPrice). Doing so gives the QueryException below.

Is there something wrong with my configuration?

I debugged the code and at some point it is merging the CountryPrice entity (with the country and price in it's map) into the target, but it looks like the value of the Map.entry is being passed for merging into the target object ( while it should be the Map.entry?

Caused by: Exception [EclipseLink-6157] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.QueryException
Exception Description: Element [Entity{id=419692} Price@116fc46] is being added to a map without a key. This generally means the database does not hold a key that is expected.
at org.eclipse.persistence.exceptions.QueryException.cannotAddE lementWithoutKeyToMap(
at org.eclipse.persistence.internal.queries.MapContainerPolicy. addInto(
at org.eclipse.persistence.internal.queries.ContainerPolicy.add Into(
at org.eclipse.persistence.internal.queries.MapContainerPolicy. addInto(
at org.eclipse.persistence.internal.queries.MappedKeyMapContain erPolicy.addInto(
at org.eclipse.persistence.mappings.CollectionMapping.mergeChan gesIntoObject(
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.m ergeChangesIntoObject(
at org.eclipse.persistence.internal.sessions.MergeManager.merge ChangesOfWorkingCopyIntoOriginal(
at org.eclipse.persistence.internal.sessions.MergeManager.merge Changes(
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mer geChangesIntoParent(
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.mergeChangesIntoParent(RepeatableWriteUnitOfWork.jav a:293)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitRootUnitOfWork( 211)
at mitAndResume(
at org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionImpl.commitInternal(
Re: cannotAddElementWithoutKeyToMap [message #543170 is a reply to message #542557] Mon, 28 June 2010 15:35 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Seems to be a bug.

Can you try the 2.1 release to see if the issue still occurs.

If it does, please log the bug and include your classes and the code for your test case.

James : Wiki : Book : Blog : Twitter
Previous Topic:Eclipse Dali Refactoring Participation
Next Topic:Moxy JAXB annotations for closure table relationship
Goto Forum:

Current Time: Wed Apr 25 14:48:06 GMT 2018

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

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