geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Viet Hung Nguyen <vnguye...@uky.edu>
Subject ejb 3.0--connecting to a DB
Date Tue, 19 Jun 2007 20:23:59 GMT
I am unable to get a handle on a EntityManagerFactory.

I have the following configuration using Derby as the DB on Geronimo 2.0:

--*persistence.xml *which is in the JAR file under META-INF--
<?xml version="1.0" encoding="UTF-8"?>
<persistence     xmlns="http://java.sun.com/xml/ns/persistence"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
version="1.0"
                
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="BankPU" transaction-type="JTA">
        <description>Entity Beans for Bank</description>
        
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <class>org.apache.geronimo.samples.bank.ejb.Account</class>
        <class>org.apache.geronimo.samples.bank.ejb.Customer</class>
        <class>org.apache.geronimo.samples.bank.ejb.ExchangeRate</class>
        <exclude-unlisted-classes />
        <properties>
            <property name="openjpa.ConnectionURL" 
value="jdbc:derby:BankDB" />
            <property name="openjpa.ConnectionDriverName" 
value="org.apache.derby.jdbc.EmbeddedDriver" />
            <property name="openjpa.ConnectionUserName" value="system" />
            <property name="openjpa.ConnectionPassword" value="manager" />
            <property name="openjpa.Log" value="DefaultLevel=INFO" />
            <property name="openjpa.AutoDetach" value="close" />
            <property name="openjpa.DetachState" value="all" />
            <property name="openjpa.DataCache" value="false" />
            <property name="openjpa.Optimistic" value="true" />
            <property name="openjpa.Multithreaded" value="true" />
            <property name="openjpa.TransactionMode" value="local" />
            <property name="openjpa.NontransactionalRead" value="true" />
            <property name="openjpa.RestoreState" value="all" />
            <property name="openjpa.jdbc.SynchronizeMappings" 
value="false" />
        </properties>
        <jta-data-source>BankPool</jta-data-source>
        <non-jta-data-source>NoTxDatasource</non-jta-data-source>
    </persistence-unit>
</persistence>

--*web.xml*--
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">
   
    <welcome-file-list>
        <welcome-file>/jsp/index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <display-name>CustomerServiceServlet</display-name>
        <servlet-name>CustomerServiceServlet</servlet-name>
        
<servlet-class>org.apache.geronimo.samples.bank.web.CustomerServiceServlet</servlet-class>
    </servlet>
   
    <servlet>
        <display-name>CommonServiceServlet</display-name>
        <servlet-name>CommonServiceServlet</servlet-name>
        
<servlet-class>org.apache.geronimo.samples.bank.web.CommonServiceServlet</servlet-class>
    </servlet>
     
    <servlet-mapping>
        <servlet-name>CustomerServiceServlet</servlet-name>
        <url-pattern>/customer_info</url-pattern>
    </servlet-mapping>
   
    <servlet-mapping>
        <servlet-name>CommonServiceServlet</servlet-name>
        <url-pattern>/exchange_rates</url-pattern>
    </servlet-mapping>

    <persistence-unit-ref>
        <persistence-unit-ref-name>BankPU</persistence-unit-ref-name>
        <persistence-unit-name>BankPU</persistence-unit-name>
    </persistence-unit-ref>
</web-app>

Here is a snippet of code of how I am I trying to access the EMF:

@Stateless
public class BankManagerFacadeBean {
   
    @PersistenceUnit(unitName="BankPU")
    protected EntityManagerFactory emf;

    // other stuff

    public Collection<Account> getAccountInformation(String customerId) {
        EntityManager em = emf.createEntityManager();

        String query = "SELECT * FROM Account WHERE customerId='" + 
customerId + "'";
        Collection<Account> accountBeanList = 
(Collection<Account>)em.createQuery( query ).getResultList();

        em.close();
        return accountBeanList;
    }
}

However, 'emf' is actually null after I had mapped BankPU to it.

Is there something that I am missing?

Thanks,
Viet Nguyen

Mime
View raw message