jpa - Entity Update throws NPE for @ElementColection of Map -
i have department , employee entities. employee table has 3 columns:
- department_id
- key
- value
inserted null value in insert non null key in employee table. received nullpointerexception
during update non null value existing key during prop.put(key, value)
:
java.lang.nullpointerexception @ java.util.hashtable.put(hashtable.java:514) @ org.eclipse.persistence.indirection.indirectmap.put(indirectmap.java:543) @ org.eclipse.persistence.internal.queries.mapcontainerpolicy.addinto(mapcontainerpolicy.java:131) @ org.eclipse.persistence.internal.queries.mappedkeymapcontainerpolicy.addinto(mappedkeymapcontainerpolicy.java:196) @ org.eclipse.persistence.queries.datareadquery.executenoncursor(datareadquery.java:226) @ org.eclipse.persistence.queries.datareadquery.executedatabasequery(datareadquery.java:152) @ org.eclipse.persistence.queries.databasequery.execute(databasequery.java:899) @ org.eclipse.persistence.queries.datareadquery.execute(datareadquery.java:137) @ org.eclipse.persistence.queries.databasequery.executeinunitofwork(databasequery.java:798) @ org.eclipse.persistence.internal.sessions.unitofworkimpl.internalexecutequery(unitofworkimpl.java:2896) @ org.eclipse.persistence.internal.sessions.abstractsession.executequery(abstractsession.java:1804) @ org.eclipse.persistence.internal.sessions.abstractsession.executequery(abstractsession.java:1786) @ org.eclipse.persistence.internal.indirection.querybasedvalueholder.instantiate(querybasedvalueholder.java:129) @ org.eclipse.persistence.internal.indirection.querybasedvalueholder.instantiate(querybasedvalueholder.java:116) @ org.eclipse.persistence.internal.indirection.databasevalueholder.getvalue(databasevalueholder.java:89) @ org.eclipse.persistence.internal.indirection.unitofworkvalueholder.instantiateimpl(unitofworkvalueholder.java:173) @ org.eclipse.persistence.internal.indirection.unitofworkvalueholder.instantiate(unitofworkvalueholder.java:234) @ org.eclipse.persistence.internal.indirection.databasevalueholder.getvalue(databasevalueholder.java:89) @ org.eclipse.persistence.indirection.indirectmap.builddelegate(indirectmap.java:109) @ org.eclipse.persistence.indirection.indirectmap.getdelegate(indirectmap.java:329) @ org.eclipse.persistence.indirection.indirectmap.put(indirectmap.java:543)
eclipselink version 2.5.2
i have department , employee entities , department entity class has following relationship employee entity:
@entity @table(name = "department" uniqueconstraints = { @uniqueconstraint(columnnames = { "name" }) }) @namedqueries( { @namedquery(name = department.findall", query = "select d department d"), @namedquery(name = department.findbyname", query = "select d department d d.name = :name")}) public class department implements serializable { @elementcollection @mapkeycolumn( name = "key") @column( name = "value") @collectiontable(name="department_prop", joincolumns = @joincolumn(name= "department_id)) private final map<string, string> props = new hashmap(); public map<string, string> getproperties() { return properties; }
no methods or persistent instance variables of entity class may final
. removed modifier props
, mapping annotations fine.
be aware in java version 7 can't put null values because java.util.hashtable
doesn't allow it, , can see in exception log implementation of map eclipselink uses. see this java oficial doc.
Comments
Post a Comment