我在两个持久性实体ManyToMany
和Traveller
之间存在Address
关系。每位旅行者必须有3个地址:礼物,永久和参考人地址。我试过这段代码:
Traveller
实体:
@ManyToMany(mappedBy = "travellers")
private Address presentAdd, permanentAdd, refPersonAdd;
Address
实体:
@ManyToMany
private List<Traveller> travellers;
但是显示了这个例外:
Grave: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare
method
Grave: Exception while preparing the app
Grave: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.2.v20111125-
r10461): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [visasMarketingPU] failed.
Internal Exception: Exception [EclipseLink-7214] (Eclipse Persistence Services -
2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The target entity of the relationship attribute [permanentAdd] on
the class [class com.gis.visasmarketing.entities.Traveller] cannot be determined. When
not using generics, ensure the target entity is defined on the relationship mapping.
javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse
Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [visasMarketingPU] failed.
Internal Exception: Exception [EclipseLink-7214] (Eclipse Persistence Services -
2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The target entity of the relationship attribute [permanentAdd] on
the class [class com.gis.visasmarketing.entities.Traveller] cannot be determined. When
not using generics, ensure the target entity is defined on the relationship
mapping.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.
predeploy(EntityManagerSetupImpl.java:1402)
at org.eclipse.persistence.jpa.PersistenceProvider.
createContainerEntityManagerFactory(PersistenceProvider.java:208)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.
loadPU(PersistenceUnitLoader.java:206)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>
(PersistenceUnitLoader.java:120)
at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)
at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.
iteratePUDs(JPADeployer.java:495)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
at com.sun.enterprise.v3.server.ApplicationLifecycle.
prepareModule(ApplicationLifecycle.java:871)
at com.sun.enterprise.v3.server.ApplicationLifecycle.
deploy(ApplicationLifecycle.java:410)
at com.sun.enterprise.v3.server.ApplicationLifecycle.
deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.
execute(CommandRunnerImpl.java:348)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.
doCommand(CommandRunnerImpl.java:363)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.
doCommand(CommandRunnerImpl.java:1085)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.
access$1200(CommandRunnerImpl.java:95)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.
execute(CommandRunnerImpl.java:1291)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.
execute(CommandRunnerImpl.java:1259)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.
call(ContainerMapper.java:354)
at com.sun.enterprise.v3.services.impl.ContainerMapper.
service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.
execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter
(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.
execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.
doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:744)
Caused by: Exception [EclipseLink-28018]
(Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit
[visasMarketingPU] failed.
Internal Exception: Exception [EclipseLink-7214]
(Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.
ValidationException
Exception Description: The target entity of the relationship attribute
[permanentAdd] on the class [class com.gis.visasmarketing.entities.Traveller]
cannot be determined. When not using generics, ensure the target entity
is defined on the relationship mapping.
at org.eclipse.persistence.exceptions.EntityManagerSetupException.
predeployFailed(EntityManagerSetupException.java:221)
... 38 more
Caused by: Exception [EclipseLink-7214]
(Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: The target entity of the relationship attribute
[permanentAdd] on the class [class com.gis.visasmarketing.entities.Traveller]
cannot be determined. When not using generics, ensure the target entity is defined
on the relationship mapping.
at org.eclipse.persistence.exceptions.ValidationException.
unableToDetermineTargetEntity(ValidationException.java:1959)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.
CollectionAccessor.getReferenceClass(CollectionAccessor.java:458)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.
ClassAccessor.addAccessor(ClassAccessor.java:277)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.
ClassAccessor.addAccessorFields(ClassAccessor.java:415)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.
ClassAccessor.addAccessors(ClassAccessor.java:387)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.
ClassAccessor.preProcess(ClassAccessor.java:1134)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.
MappedSuperclassAccessor.preProcess(MappedSuperclassAccessor.java:682)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.
EntityAccessor.preProcess(EntityAccessor.java:554)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.
processStage1(MetadataProject.java:1608)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.
processORMMetadata(MetadataProcessor.java:531)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.
processORMetadata(PersistenceUnitProcessor.java:526)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.
predeploy(EntityManagerSetupImpl.java:1337)
... 37 more
我需要你的帮助
答案 0 :(得分:0)
你不能像这样定义多对多。但是你想要做的事情可以通过
来实现更改您的旅行者实体;
@ManyToMany(mappedBy = "travellers")
private List<Address> addresses;
并在AddressType中添加addressType(最好是Enum):
private AddressType type;
public Enum AddressType{
PRESENT,PERMANENT,REFERENCE_PERSON
}
答案 1 :(得分:0)
我在Traveller
实体中定义了这样的属性:
private Address presentAdd, permanentAdd, refPersonAddTun, refPersonAddThai;
并在Address
实体中:
private Traveller traveller;