我有Entity
个Map
字段映射为嵌入式集合:
@Entity
public class PhysicalTp implements Serializable {
...
@Id @Column(name="PTP_ID")
private long id;
@ElementCollection(fetch=FetchType.LAZY)
@CollectionTable(name="IUT_PTP_TRANSMISSION_PARAMETER",
joinColumns={ @JoinColumn(name="TMP_PTP_ID", referencedColumnName="PTP_ID") })
@Column(name="TMP_VALUE")
private Map<TransmissionParameter,String> transmissionParameters;
...
}
密钥TransmissionParameter
是一个嵌入式实体,由一个基本字段和一个FK字段组成:
@Embeddable
public class TransmissionParameter implements Serializable {
@Basic(optional=false)
@Column(name="TMP_NAME",nullable=false)
private String name;
@ManyToOne(optional=false)
@JoinColumn(name="TMP_CLR_ID",nullable=false)
private CatLayerRate layerRate;
... (hashCode, equals, getters, setters, etc...)
}
CatLayerRate
是一个简单的字典实体:
@Entity
public class CatLayerRate implements Serializable {
private static final long serialVersionUID = 1L;
@Id @Column(name="CLR_ID")
private long id;
@Column(name="CLR_DESC")
private String desc;
@Basic(optional=false)
@Column(name="CLR_NAME", nullable=false)
private String name;
... (hashCode, equals, getters, setters)
}
除了删除实体之外,所有映射都运行良好。当我尝试删除任何PhysicalTp
实例时,Eclipselink会抛出异常:
Exception Description: A NullPointerException was thrown while extracting a value from the instance variable [null] in the object [PhysicalTp].
Internal Exception: java.lang.NullPointerException
Mapping: org.eclipse.persistence.mappings.AggregateObjectMapping[null]
Descriptor: RelationalDescriptor(PhysicalTp --> [DatabaseTable(IUT_PHYSICAL_TP)])
P.S。我无法将TransmissionParameter
映射为@OneToMany
实体,因为它被各种实体使用,并且每个实体都必须映射到它自己的表。
EclipseLink 2.5.1。
Salu2, 安东
UPD:完整的堆栈跟踪(与其他实体一起复制)
javax.persistence.RollbackException: Exception [EclipseLink-69] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A NullPointerException was thrown while extracting a value from the instance variable [null] in the object [eclipselink.bugs.TestEmbeddedMapKeyBug$MainEntity].
Internal Exception: java.lang.NullPointerException
Mapping: org.eclipse.persistence.mappings.AggregateObjectMapping[null]
Descriptor: RelationalDescriptor(eclipselink.bugs.TestEmbeddedMapKeyBug$MainEntity --> [DatabaseTable(TESTEMBEDDEDMAPKEYBUG$MAINENTITY)])
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:157)
at eclipselink.bugs.TestEmbeddedMapKeyBug.testEmbeddedMapKeyBug(TestEmbeddedMapKeyBug.java:202)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: Exception [EclipseLink-69] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A NullPointerException was thrown while extracting a value from the instance variable [null] in the object [eclipselink.bugs.TestEmbeddedMapKeyBug$MainEntity].
Internal Exception: java.lang.NullPointerException
Mapping: org.eclipse.persistence.mappings.AggregateObjectMapping[null]
Descriptor: RelationalDescriptor(eclipselink.bugs.TestEmbeddedMapKeyBug$MainEntity --> [DatabaseTable(TESTEMBEDDEDMAPKEYBUG$MAINENTITY)])
at org.eclipse.persistence.exceptions.DescriptorException.nullPointerWhileGettingValueThruInstanceVariableAccessor(DescriptorException.java:1277)
at org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor.getAttributeValueFromObject(InstanceVariableAttributeAccessor.java:88)
at org.eclipse.persistence.mappings.DatabaseMapping.getAttributeValueFromObject(DatabaseMapping.java:630)
at org.eclipse.persistence.mappings.DatabaseMapping.getRealAttributeValueFromObject(DatabaseMapping.java:786)
at org.eclipse.persistence.mappings.AggregateObjectMapping.earlyPreDelete(AggregateObjectMapping.java:1043)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1412)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1531)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:277)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1169)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:132)
... 25 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor.getAttributeValueFromObject(InstanceVariableAttributeAccessor.java:76)
... 33 more