扩展在另一个持久性单元中定义的类

时间:2014-08-12 15:13:22

标签: java hibernate jpa-2.0

我有一个类User,它位于持久性单元idmalight中。我必须创建一个扩展用户的类CMNUser,但必须使用持久性单元cmn

首先,有可能吗?

如果是,这里是类的片段:

@Entity
@Audited
@Table( name = "NETHZ_USER" )
@Inheritance( strategy = InheritanceType.JOINED )
public class User extends PersistentObject
{
  fields
  getters
  setters
}


@Entity
@Table( name = "CMN_USER" )
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
public class CMNUser extends User
{
    @ManyToMany( fetch = FetchType.LAZY )
    @JoinTable( name = "CMN_MAP_USER_TO_DELEGATE" )
    private Set< User >         delegates;

    getter
    setter
}

当我尝试部署应用程序时,我收到错误:

     [exec] [#|2014-08-12T16:41:26.755+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=67;_ThreadName=Thread-2;|Exception while invoking class org.glassfish.persistence.jpa.JPADeploye
r prepare method|#]
     [exec]
     [exec] [#|2014-08-12T16:41:26.755+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=67;_ThreadName=Thread-2;|Exception while preparing the app|#]
     [exec]
     [exec] [#|2014-08-12T16:41:26.755+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=67;_ThreadName=Thread-2;|[PersistenceUnit: cmnPersistenceUnit] Unable to build EntityManagerFact
ory
     [exec] javax.persistence.PersistenceException: [PersistenceUnit: cmnPersistenceUnit] Unable to build EntityManagerFactory
     [exec]     at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
     [exec]     at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
     [exec]     at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
     [exec]     at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:206)
     [exec]     at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:120)
     [exec]     at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)
     [exec]     at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:495)
     [exec]     at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)
     [exec]     at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
     [exec]     at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)
     [exec]     at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
     [exec]     at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
     [exec]     at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
     [exec]     at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
     [exec]     at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
     [exec]     at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
     [exec]     at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
     [exec]     at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
     [exec]     at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
     [exec]     at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
     [exec]     at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
     [exec]     at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
     [exec]     at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
     [exec]     at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
     [exec]     at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
     [exec]     at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
     [exec]     at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
     [exec]     at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
     [exec]     at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
     [exec]     at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
     [exec]     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
     [exec]     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
     [exec]     at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
     [exec]     at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
     [exec]     at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
     [exec]     at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
     [exec]     at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
     [exec]     at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
     [exec]     at java.lang.Thread.run(Thread.java:745)
     [exec] Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: ch.ethz.id.wai.idmanlight.bo.User.permissions[ch.ethz.id.wai.idmanlight.bo.Permission]
     [exec]     at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1057)
     [exec]     at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:733)
     [exec]     at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:668)
     [exec]     at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
     [exec]     at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1586)
     [exec]     at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1344)
     [exec]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1730)
     [exec]     at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
     [exec]     at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
     [exec]     ... 38 more
     [exec] |#]

权限在User class中定义为

@ManyToMany
private Set< Permission >   permissions;

这是因为不同的PU和实体CMNUser不知道父类中设置的字段(因此不可能做这样的事情)或者还有其他原因吗?

0 个答案:

没有答案