users@glassfish.java.net

JTA with EJB Lite 3.1 Error

From: <forums_at_java.net>
Date: Fri, 18 Mar 2011 07:51:38 -0500 (CDT)

I've a doubt with EJB Lite 3.1 embeddable:
I'm using EJB Lite for a app JSE; the call of EJB components are OK! The
problem only appear when I try
do a connection using JTA for the database.
See:

<code>
@Stateless
@DataSourceDefinition(name="java:app/jdbc/estudo",
                      databaseName="estudo",
                      password="123456",
                      user="postgres",
                      className="org.postgresql.Driver",
                      portNumber=5432,
                      serverName="localhost")
public class DataSourceCustomBean {
    @PersistenceContext(unitName="ExemploEJbPU")
    private EntityManager em;
</code>
This datasource is who provides the data-source-name for references in the
persistence.xml. See the persistence.xml:
<code>
<?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="ExemploEJbPU" transaction-type="JTA">
      <jta-data-source>java:app/jdbc/estudo</jta-data-source>
   
   
    <properties>
     
      <property name="eclipselink.ddl-generation" value="update"/>
    </properties>
  </persistence-unit>
</persistence>
</code>
The call this component is definied below:
<code>
EJBContainer container = EJBContainer.createEJBContainer();
     
 InitialContext context = (InitialContext) container.getContext();
       
 DataSourceCustom dataSource = (DataSourceCustom)
context.lookup("java:global/classes/DataSourceCustomBean");
</code>
In the moment I try run the application, appear the following stack,
<code>
SEVERE: Exception while invoking class
org.glassfish.persistence.jpa.JPADeployer prepare method
java.lang.RuntimeException: javax.naming.NamingException: Lookup failed for
'java:app/jdbc/estudo' in SerialContext  [Root exception is
javax.naming.NamingException: Invocation exception: Got null
ComponentInvocation ]
        at
org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:111)
        at
org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:130)
        at
org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:96)
        at
org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:121)
        at
com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:644)
        at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:296)
        at
org.glassfish.kernel.embedded.EmbeddedDeployerImpl.deploy(EmbeddedDeployerImpl.java:214)
        at
org.glassfish.kernel.embedded.EmbeddedDeployerImpl.deploy(EmbeddedDeployerImpl.java:144)
        at
org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:128)
        at
org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:120)
        at
javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:102)
        at
javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:78)
        at exemploejb.Main.main(Main.java:32)

</code>

Waiting for suggestions. Tks


--
[Message sent by forum member 'fabiomedeirosf']
View Post: http://forums.java.net/node/782893