[jboss-user] [Datasource Configuration] - @PersistenceUnit don't return entityManager

James Wong do-not-reply at jboss.com
Mon Mar 4 11:16:59 EST 2013


James Wong [https://community.jboss.org/people/jwong22] created the discussion

"@PersistenceUnit don't return entityManager"

To view the discussion, visit: https://community.jboss.org/message/800638#800638

--------------------------------------------------------------
Hello 
   I have a problem with the annotation @PersistenceUnit.
   I use it to define my EntityManager but it always return null.
I use the server JBOSS 7.1

This is my persistence.xml

<?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="eiad-ejbPU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/EiadDS</jta-data-source>
    <class>fr.eiad.business.Temps</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.show_sql" value="true" />
      <property name="hibernate.format_sql" value="true" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
    </properties>
  </persistence-unit>
</persistence>


and this is my Service.java

  @javax.persistence.PersistenceContext(unitName = "eiad-ejbPU")
  private EntityManager    entityManager;
  private static final Log log = LogFactory.getLog(TempsService.class);
 
  public void persist(final Temps temps)
  {
    log.debug("persisting Temps instance"); //$NON-NLS-1$
    entityManager.persist(temps);
  }
 
  public final Temps findById(final Integer id)
  {
    log.debug("getting User instance with id: " + id);
    try
    {
      final Temps instance = entityManager.find(Temps.class, id);
      log.debug("get successful");
      return instance;
    }
    catch (final RuntimeException re)
    {
      log.error("get failed", re);
      throw re;
    }
  }




Thanks
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800638#800638]

Start a new discussion in Datasource Configuration at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130304/7fcea441/attachment.html 


More information about the jboss-user mailing list