Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » cannotAddElementWithoutKeyToMap(Map with entities for key and value)
cannotAddElementWithoutKeyToMap [message #542557] Fri, 25 June 2010 06:35 Go to next message
Eclipse UserFriend
I have an entity containing a Map for which the key and value are both entities:

@OneToMany(cascade = ALL, orphanRemoval = true)
@JoinTable(
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 (MapContainerPolicy.java:117) 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(QueryException.java:1435)
at org.eclipse.persistence.internal.queries.MapContainerPolicy. addInto(MapContainerPolicy.java:153)
at org.eclipse.persistence.internal.queries.ContainerPolicy.add Into(ContainerPolicy.java:128)
at org.eclipse.persistence.internal.queries.MapContainerPolicy. addInto(MapContainerPolicy.java:117)
at org.eclipse.persistence.internal.queries.MappedKeyMapContain erPolicy.addInto(MappedKeyMapContainerPolicy.java:176)
at org.eclipse.persistence.mappings.CollectionMapping.mergeChan gesIntoObject(CollectionMapping.java:1291)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.m ergeChangesIntoObject(ObjectBuilder.java:2629)
at org.eclipse.persistence.internal.sessions.MergeManager.merge ChangesOfWorkingCopyIntoOriginal(MergeManager.java:631)
at org.eclipse.persistence.internal.sessions.MergeManager.merge Changes(MergeManager.java:263)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mer geChangesIntoParent(UnitOfWorkImpl.java:3239)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.mergeChangesIntoParent(RepeatableWriteUnitOfWork.jav a:293)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java: 211)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitAndResume(UnitOfWorkImpl.java:1129)
at org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionImpl.commitInternal(EntityTransactionImpl.java:84)
Re: cannotAddElementWithoutKeyToMap [message #543170 is a reply to message #542557] Mon, 28 June 2010 11:35 Go to previous message
Eclipse UserFriend
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.
Previous Topic:Eclipse Dali Refactoring Participation
Next Topic:Moxy JAXB annotations for closure table relationship
Goto Forum:
  


Current Time: Tue Jul 22 18:58:53 EDT 2025

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

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

Back to the top