users@glassfish.java.net

Re: GF3 + OpenJPA 2.0 - Enhancer not working

From: <glassfish_at_javadesktop.org>
Date: Tue, 20 Jul 2010 05:47:50 PDT

Hello again,

ok, I just finished a test, using dependency injection for the PersistenceUnit lookup, rather than a manual resource lookup.

Basically, I set up the following in my EntityManager class:

@PersistenceUnit(unitName="myApplicationPersistenceUnit")
private EntityManagerFactory emfTmp;
private EntityManagerFactory emf = Persistence.createEntityManagerFactory("myApplicationPersistenceUnit");

persistence.xml:

<persistence
  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_1_0.xsd" version="1.0">

  <persistence-unit name="myApplicationPersistenceUnit">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <jta-data-source>jdbc/MyDataSource</jta-data-source>
    <properties>
      <property name="openjpa.TransactionMode" value="managed"/>
      <property name="openjpa.ConnectionFactoryMode" value="managed"/>
      <property name="openjpa.jdbc.DBDictionary" value="mysql"/>
      <!-- <property name="openjpa.MetaDataFactory" value="jpa(Types=my.domain.entity.Class1;my.domain.entity.Class2)"/> -->
      <property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE"/>
    </properties>
  </persistence-unit>
</persistence>

The result was surprising:
the @PersistenceUnit(unitName="blablabla") annotated variable emfTmp stayed null, but the Enhancer is working. I verified this one by removing the @PersistenceUnit line and got an error message stating, that the class accessed wasn't enhanced before.

Now, how do I get the dependency injection right, so I can remove the manual resource lookup? I made sure, that the unitName given is correct.

Thanks.

kniffte
[Message sent by forum member 'kniffte']

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