users@glassfish.java.net

RE: Can't deploy an application with two persistence units

From: Martin, Ray <armart3_at_tycho.ncsc.mil>
Date: Tue, 31 Aug 2010 08:16:52 -0400

Are your data sources XA?

As soon as you go multiple data sources, XA is required.

-----Original Message-----
From: glassfish_at_javadesktop.org [mailto:glassfish_at_javadesktop.org]
Sent: Tuesday, August 31, 2010 8:10 AM
To: users_at_glassfish.dev.java.net
Subject: Can't deploy an application with two persistence units

Hi all.

I have a problem deployig a simple test application into GF3. I have the following PU references 2 databases:
<persistence>
  <persistence-unit name="Bank1PU" transaction-type="JTA">
    <jta-data-source>jdbc/Bank1</jta-data-source>
    <class>entity.bank1.Customer1</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
  </persistence-unit>
  <persistence-unit name="Bank2PU" transaction-type="JTA">
    <jta-data-source>jdbc/Bank2</jta-data-source>
    <class>entity.bank2.Customer2</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
  </persistence-unit>
</persistence>

Currently there are no references for Bank2PU in the application. And there is only one reference to Bank1PU in one of my EJBs:

@Stateless
public class Bank1Browser implements Bank1BrowserRemote {
    @PersistenceContext(name="Bank1PU")
    EntityManager em;
    ...
}

When I deply it I receive the following error in the log:

[#|2010-08-31T15:11:27.602+0400|SEVERE|glassfish3.0.1|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=30;_ThreadName=Thread-1;|Exception while invoking class org.glassfish.javaee.full.deployment.EarDeployer prepare method
org.glassfish.deployment.common.DeploymentException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [Bank1PU] in the scope of the module called [BankTransfer#BankTransfer-ejb.jar]. Please verify your application.
        at org.glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:148)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:644)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:296)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
        at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
        at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
        at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
        at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [Bank1PU] in the scope of the module called [BankTransfer#BankTransfer-ejb.jar]. Please verify your application.
        at com.sun.enterprise.deployment.BundleDescriptor.findReferencedPUsViaPCRefs(BundleDescriptor.java:672)
        at com.sun.enterprise.deployment.EjbBundleDescriptor.findReferencedPUs(EjbBundleDescriptor.java:892)
        at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:103)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:644)
        at org.glassfish.javaee.full.deployment.EarDeployer.prepareBundle(EarDeployer.java:269)
        at org.glassfish.javaee.full.deployment.EarDeployer.access$200(EarDeployer.java:79)
        at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:131)
        at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:129)
        at org.glassfish.javaee.full.deployment.EarDeployer.doOnBundles(EarDeployer.java:197)
        at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllTypedBundles(EarDeployer.java:206)
        at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllBundles(EarDeployer.java:232)
        at org.glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:129)
        ... 29 more
|#]

However If I remove the second PU from persistence.xml and leave it as follows:
<persistence>
  <persistence-unit name="Bank1PU" transaction-type="JTA">
    <jta-data-source>jdbc/Bank1</jta-data-source>
    <class>entity.bank1.Customer1</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
  </persistence-unit>
</persistence>
...everything works fine!

It seems that I am missing something very simple. Does any know how to workaround the problem?
[Message sent by forum member 'svenom']

http://forums.java.net/jive/thread.jspa?messageID=481337

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net