users@glassfish.java.net

Glassfish, JPA, can't get it to work.

From: <glassfish_at_javadesktop.org>
Date: Wed, 21 May 2008 02:51:04 PDT

The EntityManger always null with:

[code]
@PersistenceContext(unitName = "punit")
private EntityManager em;
[/code]

Here is the config.
[code]
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:ns2="http://java.sun.com/xml/ns/persistence/orm" 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">
  <persistence-unit name="punit" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/public_PostgreSQL</jta-data-source>
    <class>com.test.MyEntity</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/test"/>
      <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
      <property name="hibernate.connection.password" value="test"/>
      <property name="hibernate.connection.username" value="test"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>
[/code]

Hrere is the code:

[code]
public class DAO {
    @PersistenceContext(unitName = "punit")
    private EntityManager em;

    public EntityManager getEm() {return em;}

    public void setEm(EntityManager em) {this.em = em;}

    public void submit(MyEntity e) {
        em.persist(e); // em is always null
    }
}
[/code]

I have a feeling I am doing something very wrong?
Any tips appreciated.

Thanks.
[Message sent by forum member 'marlor' (marlor)]

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