users@glassfish.java.net

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

From: Sahoo <Sahoo_at_Sun.COM>
Date: Mon, 07 Sep 2009 09:43:38 +0530

You are using the wrong annotation attributes. Write this in your code:

@PersistenceContext(unitName="VoiceMailProvider-ejbPU")
private EntityManager em_FirstDB;
@PersistenceContext(unitName="Asterisk-ejbPU")
private EntityManager em_SecondDB;


Sahoo
Paul Mancheno H. wrote:
> 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>
>
> When I had just one PU then I wrote in my EJB:
>
> @PersistenceContext(name="FirstDB-ejbPU")
> private EntityManager em;
>
> And everything was ok, now I am trying with:
>
> @PersistenceContext(name="FirstDB-ejbPU")
> private EntityManager em_FirstDB;
> @PersistenceContext(name="SecondDB-ejbPU")
> private EntityManager em_SecondDB;
>
> But I receive the exception in the attach. 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?
>
> A lot of thaks.
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net