问题描述
大家好!
我正在尝试将一对多关联映射到使用@Inheritance(strategy=InheritanceType.JOINED)
I'm trying to map an association one-to-many to an entity that is mappes with @Inheritance(strategy=InheritanceType.JOINED)
....
@ManyToMany
@JoinTable(name = "S_MC_CC_CONTRATTIRAPPORTI",
joinColumns = @JoinColumn(name = "COD_MULTICHANNELID"),
inverseJoinColumns = @JoinColumn(name = "COD_RAPPORTO")
)
private Collection<Rapporto> rapporti;
...
@Entity
@Table(name = "S_MC_CC_RAPPORTI")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="COD_TIPORAPPORTO")
public abstract class Rapporto implements Serializable {
问题是我收到此异常异常描述:缺少类型为[class java.lang.String]的指标字段值[1]的类.
THe problem is that I receive this exceptionException Description: Missing class for indicator field value [1] of type [class java.lang.String].
我认为JPA试图为该类标识一个DiscriminatorValue.我想加载所有扩展超类的对象.
I think that JPA tries to identify a DiscriminatorValue for the class.I would like to load all the Objects that extend the super class.
有可能吗?
更多信息:这是该协会的所有者
More information: this is the owner of the association
@Entity
@Table(name = "S_MC_CC_CONTRATTI")
public class Contratto implements Serializable {
@Id
@Column(name = "COD_MULTICHANNELID")
private String multichannelId;
@ManyToMany()
@JoinTable(name = "S_MC_CC_CONTRATTIRAPPORTI", joinColumns = @JoinColumn(name = "COD_MULTICHANNELID"), inverseJoinColumns = @JoinColumn(name = "COD_RAPPORTO"))
private Collection<Rapporto> rapporti;
这是多对多关联的抽象类
This is the abstract class of the many-to-many association
@Entity
@Table(name = "S_MC_CC_RAPPORTI")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="COD_TIPORAPPORTO")
public abstract class Rapporto implements Serializable {
private static final long serialVersionUID = -5567166522882040440L;
@Id
@Column(name = "COD_RAPPORTO")
protected Long codiceRapporto;
这是两个子类:
@Entity
@Table(name="S_MC_CC_CCCLIENTI")
@DiscriminatorValue("1 ")
public class ContoCorrente extends Rapporto {
private static final long serialVersionUID = -3380622649760983262L;
@Column(name = "DESC_DIVISA")
private String divisa;
@Entity
@Table(name = "S_MC_CC_RAPPORTI")
@DiscriminatorValue("6 ")
public class NumeroPortafoglioEstero extends Rapporto {
private static final long serialVersionUID = 6869743707936663970L;
/**
* @param filiale
* @param categoria
* @param conto
*/
public NumeroPortafoglioEstero(Filiale filiale, String categoria, String conto) {
super(filiale, categoria, conto);
}
这是一个例外:
Local Exception Stack:
Exception [EclipseLink-43] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class for indicator field value [1] of type [class java.lang.String].
Descriptor: RelationalDescriptor(it.alten.intesasanpaolo.contratto.domain.core.rapporto.Rapporto --> [DatabaseTable(S_MC_CC_RAPPORTI)])
at org.eclipse.persistence.exceptions.DescriptorException.missingClassForIndicatorFieldValue(DescriptorException.java:921)
at org.eclipse.persistence.descriptors.InheritancePolicy.classFromValue(InheritancePolicy.java:355)
at org.eclipse.persistence.descriptors.InheritancePolicy.classFromRow(InheritancePolicy.java:342)
at org.eclipse.persistence.descriptors.InheritancePolicy.selectAllRowUsingDefaultMultipleTableSubclassRead(InheritancePolicy.java:1303)
at org.eclipse.persistence.descriptors.InheritancePolicy.selectAllRowUsingMultipleTableSubclassRead(InheritancePolicy.java:1402)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2493)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:407)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1076)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:740)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1036)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:380)
at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2392)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1291)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1273)
at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:96)
at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:86)
at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:83)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:160)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:220)
at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:83)
at org.eclipse.persistence.indirection.IndirectList.buildDelegate(IndirectList.java:237)
at org.eclipse.persistence.indirection.IndirectList.getDelegate(IndirectList.java:398)
at org.eclipse.persistence.indirection.IndirectList.toArray(IndirectList.java:741)
at it.alten.intesasanpaolo.contratto.domain.core.anagrafica.Contratto.toString(Contratto.java:262)
at java.lang.String.valueOf(String.java:2827)
at java.io.PrintStream.println(PrintStream.java:771)
at it.alten.intesasanpaolo.contratto.dao.core.anagrafica.TestContrattoDaoJpaImpl.testGetItemByID(TestContrattoDaoJpaImpl.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
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)
亲切的问候马西莫
推荐答案
继承层次结构中的每个实体都必须是一个用@Entity
注释并且具有@DiscriminatorValue
Each entity in the inheritance hierarchy must be a class that is annotated with @Entity
and has a @DiscriminatorValue
这篇关于JPA与具有@Inheritance(strategy = InheritanceType.JOINED)的实体的一对多关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!