users@glassfish.java.net

More than one persistence unit in Glassfishv3

From: <glassfish_at_javadesktop.org>
Date: Sat, 05 Sep 2009 19:00:58 PDT

Hi friends.

How do I can use more than one Persistence Unit in Glassfish v3?

I am using Glassfishv3 (with Netbeans6.8M1) and I wanna use more than one persistence unit, my persistence.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="VoiceMailProvider-ejbPU" transaction-type="JTA">
    <jta-data-source>jdbc/__PostgreSqlPool</jta-data-source>
    <class>org.pepo.entidades.etapa.Arquitectura</class>
    <class>org.pepo.entidades.etapa.Comando</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
  <persistence-unit name="Asterisk-ejbPU" transaction-type="JTA">
    <jta-data-source>jdbc/__Asterisk</jta-data-source>
    <class>org.pepo.entidades.otherDB.VoicemailUsers</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

But I receive this exception:

GRAVE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-unit-ref-name [VoiceMailProvider-ejbPU] in scope of the module called [/home/pepo/NetBeansProjects/VoiceMailProvider/VoiceMailProvider-ejb/build/jar/]. Please verify your application.
        at com.sun.enterprise.deployment.BundleDescriptor.findReferencedPUsViaPURefs(BundleDescriptor.java:613)
        at com.sun.enterprise.deployment.EjbBundleDescriptor.findReferencedPUs(EjbBundleDescriptor.java:891)
        at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:100)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:603)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:251)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:174)
        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:270)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$4.execute(CommandRunnerImpl.java:422)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:437)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:524)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:140)
        at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:313)
        at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:180)
        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:208)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:752)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:660)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:911)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:164)
        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.NIOContext.execute(NIOContext.java:510)
        at com.sun.grizzly.SelectorHandlerRunner.handleSelectedKey(SelectorHandlerRunner.java:357)
        at com.sun.grizzly.SelectorHandlerRunner.handleSelectedKeys(SelectorHandlerRunner.java:257)
        at com.sun.grizzly.SelectorHandlerRunner.doSelect(SelectorHandlerRunner.java:194)
        at com.sun.grizzly.SelectorHandlerRunner.run(SelectorHandlerRunner.java:129)
        at com.sun.grizzly.util.FixedThreadPool$BasicWorker.dowork(FixedThreadPool.java:379)
        at com.sun.grizzly.util.FixedThreadPool$BasicWorker.run(FixedThreadPool.java:360)
        at java.lang.Thread.run(Thread.java:619)
GRAVE: Exception while preparing the app

I thing that there is something wrong when I create the new entity because it try to use the first Persistence Unit.

How do I can use more than one Persistence Unit in Glassfish v3?
[Message sent by forum member 'p3p0' (pepo_at_linuxmail.org)]

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