Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] A null value can not be used as a key in a container of type [class java.util.Hashtable]

The problem is that because you have EAGER set on all the mappings 
EclipseLink must resolve the cycle you have in the relationships when
building the objects.  At the point of building the OneToMany the Embedded
mapping has not been built yet, so is still null.

Not sure why you did not get the same error in TopLink Essentials, it would
have the same issue.

If you move the ManyToOne below the Embedded attribute in your code, it will
most likely fix the issue.
You could also use LAZY on the relationships, which is always strongly
recommended.
There is a weight property in DatabaseMapping that controls the order of
mappings, you could set this to 2 for the AggregateObjectMapping for the
Embedded using a DescriptorCustomizer.  Please log a bug for this, as
EclipseLink should be using 2 for Embedded mappings by default.




polvo wrote:
> 
> After upgrading from the final release of Toplink Essentials, I got the
> following error with EclipseLink (I've tried three different versions.)
> All three versions returned the error. I never had this problem with
> Toplink Essentials.
> 
> <pre>Exception [EclipseLink-6150] (Eclipse Persistence Services -
> 2.2.0.v20100819-r8063):
> org.eclipse.persistence.exceptions.ValidationException
> Exception Description: A null value can not be used as a key in a
> container of type [class java.util.Hashtable].
> Ensure your key values for the objects of type [class
> com.pvconfigurator.core.domain.VoltageConfiguration] 
> can not be null.</pre>
> 
> The full stacktrace is:
> 
> <pre>
> Caused by: Exception [EclipseLink-6150] (Eclipse Persistence Services -
> 2.2.0.v20100819-r8063):
> org.eclipse.persistence.exceptions.ValidationException
> Exception Description: A null value can not be used as a key in a
> container of type [class java.util.Hashtable]. Ensure your key values for
> the objects of type [class
> com.pvconfigurator.core.domain.VoltageConfiguration] can not be null.
> 	at
> org.eclipse.persistence.exceptions.QueryException.mapKeyIsNull(QueryException.java:749)
> 	at
> org.eclipse.persistence.internal.queries.MapContainerPolicy.addInto(MapContainerPolicy.java:138)
> 	at
> org.eclipse.persistence.internal.queries.ContainerPolicy.addInto(ContainerPolicy.java:132)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectsInto(ObjectBuilder.java:898)
> 	at
> org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:426)
> 	at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1074)
> 	at
> org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:764)
> 	at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1034)
> 	at
> org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:383)
> 	at
> org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2402)
> 	at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1301)
> 	at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1283)
> 	at
> org.eclipse.persistence.internal.indirection.NoIndirectionPolicy.valueFromQuery(NoIndirectionPolicy.java:299)
> 	at
> org.eclipse.persistence.mappings.ForeignReferenceMapping.valueFromRowInternal(ForeignReferenceMapping.java:1848)
> 	at
> org.eclipse.persistence.mappings.ForeignReferenceMapping.valueFromRow(ForeignReferenceMapping.java:1738)
> 	at
> org.eclipse.persistence.mappings.DatabaseMapping.readFromRowIntoObject(DatabaseMapping.java:1283)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildAttributesIntoObject(ObjectBuilder.java:342)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:704)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:497)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:454)
> 	at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:721)
> 	at
> org.eclipse.persistence.queries.ReadObjectQuery.executeObjectLevelReadQuery(ReadObjectQuery.java:453)
> 	at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1074)
> 	at
> org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:764)
> 	at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1034)
> 	at
> org.eclipse.persistence.queries.ReadObjectQuery.execute(ReadObjectQuery.java:412)
> 	at
> org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2402)
> 	at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1301)
> 	at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1283)
> 	at
> org.eclipse.persistence.internal.indirection.NoIndirectionPolicy.valueFromQuery(NoIndirectionPolicy.java:299)
> 	at
> org.eclipse.persistence.mappings.ForeignReferenceMapping.valueFromRowInternal(ForeignReferenceMapping.java:1848)
> 	at
> org.eclipse.persistence.mappings.OneToOneMapping.valueFromRowInternal(OneToOneMapping.java:1622)
> 	at
> org.eclipse.persistence.mappings.ForeignReferenceMapping.valueFromRow(ForeignReferenceMapping.java:1738)
> 	at
> org.eclipse.persistence.mappings.DatabaseMapping.readFromRowIntoObject(DatabaseMapping.java:1283)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildAttributesIntoObject(ObjectBuilder.java:342)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:704)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildWorkingCopyCloneNormally(ObjectBuilder.java:602)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectInUnitOfWork(ObjectBuilder.java:555)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:495)
> 	at
> org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:454)
> 	at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:721)
> 	at
> org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:726)
> 	at
> org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:423)
> 	at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1074)
> 	at
> org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:764)
> 	at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1034)
> 	at
> org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:383)
> 	at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1112)
> 	at
> org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2910)
> 	at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1301)
> 	at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1283)
> 	at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1257)
> 	at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:479)
> 	at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:714)
> </pre>
> 
> <p>The entity is a class in a hierarchy that has a map as one of it's
> properties.</p>
> 
> <p>Here's the entity code:</p>
> 
> <pre>
> @Entity(name="MyEntity")
> @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
> @DiscriminatorColumn(name="MYENTITY_TYPE")
> @Table(name="myentity")
> public class MyEntity extends OtherEntity {
>    [...]
> 
>    @JoinColumn(nullable=false)
>    @OneToMany(mappedBy="myentity", cascade=CascadeType.ALL,
> fetch=FetchType.EAGER)
>    @MapKey(name="mappedPropertyKey")
>    private Map<KeyClass, MappedPropertyClass> mappedProperties;
> 
>    [...]
> 
> 
> } </pre>
> 
> Here's the mapped entity. Note that the property that serves as the key is
> an embedded object. The "value" property of that object is what is stored
> in the database (an int). 
> 
> <pre>
> 
> @Entity(name="MappedEntity")
> @Table(name="mappedentity")
> public class MappedEntity extends BaseEntity {
> 
> 	@JoinColumn(nullable=false)
> 	@ManyToOne
> 	private MyEntity myentity;
> 
> 	@Column(nullable=false)
> 	@Embedded
> 	@AttributeOverride(name="value", column=@Column(name="MAPPEDPROPERTY"))
> 	private MappedProperty mappedPropertyKey;
> 
>         [...]
> }
> 
> </pre>
> 
> 
> <p>The query is generated by Compass (based on Lucene), which generates a
> simple "select x from [entityName] x" </p>
> 
> <p>I searched the database, and none of the columns for the key are null.
> Moreover, those columns are not nullable anyways.</p>
> 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://old.nabble.com/A-null-value-can-not-be-used-as-a-key-in-a-container-of-type--class-java.util.Hashtable--tp29586424p29641857.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top