I'm a bit confused.
-- the persistence-unit-ref is in a web.xml whereas the annotation
appears to be in an ejb
-- Since you are supplying datasources, leave out the connection
info from the properties
-- your web-app is version 2.4 whereas jpa stuff is only supported in
2.5 (although I think geronimo won't object to this)
All this being said I'd expect a lot of exceptions in the geronimo
log from trying to deploy or run this.
I don't see anything that I think would make this fail, so please
check the logs.
You are using 2.0-M6 or trunk, right?
thanks
david jencks
On Jun 19, 2007, at 4:23 PM, Viet Hung Nguyen wrote:
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