I am using Wildfly 8.1 together with a EJB Project (EJB 3.2) containing entities. When trying to inject the Entity Manager into one of my Beans i get the following:
JBAS011440: Can't find a persistence unit named null in deployment \"EntitiesProject.jar\""},
"JBAS014771: Services with missing/unavailable dependencies" => [
"jboss.deployment.unit.\"EntitiesProject.jar\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"EntitiesProject.jar\".beanmanager]",
"jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO.HandleDelegate is missing [jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO]",
"jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO.InstanceName is missing [jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO]",
"jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO.InAppClientContainer is missing [jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO]",
"jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO.Validator is missing [jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO]",
"jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO.ORB is missing [jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO]",
"jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO.ValidatorFactory is missing [jboss.naming.context.java.comp.EntitiesProject.EntitiesProject.MitarbeiterDAO]"
]
This is my SessionBean where I try to inject the EntityManager:
@Stateless
public class MitarbeiterDAO implements MitarbeiterDAORemote {
@PersistenceContext
private EntityManager em;
public int writeMitarbeiterToDB(Mitarbeiter m)
{
em.persist(m);
return m.getId();
}
}
I have specified the following persistence.xml
file which I put to "project-name"/ejbModule/META-INF.
<persistence-unit name="mitarbeiter">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
<properties>
<property-name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
Similar questions and their solutions
- Can't find persistence unit suggests to include a persistence.xml
- Injecting entityManager in Wildfly / Jboss points out that there might be another directory where my persistence.xml belongs to. I tried that directory but still got the same error message.
- Cannot find persistence unit from persistence.xml While this is not exactly the same question the solution was to add a
<provider>
to persistence.xml, but this also did not work for me
Update (see comments):
- I have tried to use @EntityManager(unitName="mitarbeiter")
instead
of just @EntityManager
- The Session Bean shown above is the only place where I try to inject
EntityManager
Update 2 (see comments of answer):
persistence.xml
is in the directoryProject/ejbModule/META-INF/
- This directory is included in the Build Path
- Somehow it's not getting deployed while other files in the same directory are (to
jar/META-INF/
). If I copy&paste it manually, it works. Why is that?
Any help and hints are greatly appreciated.