cannotAddElementWithoutKeyToMap [message #542557] |
Fri, 25 June 2010 10:35 |
Guy 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)
@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)
|
|
|
|
Powered by
FUDForum. Page generated in 0.02598 seconds