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