13

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

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 directory Project/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.

Community
  • 1
  • 1
Jbartmann
  • 1,459
  • 4
  • 24
  • 42

2 Answers2

12

A couple of possible issues:

  • Incorrect location of the persistence.xml file. Please place it inside META-INF/ directory at the root of the archive. If you use maven it would be src/main/resources/META-INF/persistence.xml.
  • Invalid persistence.xml file: you have persistence-unit tag closed in line <persistence-unit name="mitarbeiter"/> (please notice / at the end)
  • <property-name="hibernate.hbm2ddl.auto" value="create-drop"/> is invalid. I suppose you wanted: <property name="hibernate.hbm2ddl.auto" value="create-drop" />
  • also provider you are using is deprecated.

In general, the correct persistence.xml content for JPA 2.1 in your case should look like:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
  version="2.1">

  <persistence-unit name="mitarbeiter">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>

    <properties>
      <property name="hibernate.hbm2ddl.auto" value="create-drop" />
    </properties>
  </persistence-unit>
</persistence>
G. Demecki
  • 10,145
  • 3
  • 58
  • 58
  • Thank you this helped me a lot! I just did not see things like this anymore after searching for a solution for hours! It got me closer to a solution: `persistence.xml` is in the right directory as far as I know: `Projektname/ejbModule/META-INF` but it's not getting geployed while anything else in this directory is. If I copy&paste it manually it works. What could that be? – Jbartmann Oct 20 '15 at 05:50
  • @Jbartmann probably the directory is not added as source location in your build classpath – Atul Oct 20 '15 at 06:17
  • What I'm doing is: Rightclick Project -> Build Path -> Configure Build Path -> Java Build Path -> Source. There is an item `Project/ejbModule` with `Included: All`. I changed it to `Included: {selected all Folders, including META-INF}`. Still does not deploy my persistence.xml. Is that what you were talking of? I can still get it running only by copy&paste manually. As soon as I do rightclick on server -> clean it gets deleted. – Jbartmann Oct 20 '15 at 06:31
  • @Jbartmann I can see that you are using solely Eclipse. So please configure your `Deployment Assembly` (project -> Right click -> Properties -> Deployment Assembly). And add for example `META-INF` dir under `/META-INF` deploy path. But please keep in mind that when using Gradle or Maven you would be more portable/ IDE-independent. – G. Demecki Oct 20 '15 at 10:07
  • @Jbartmann you may consider accepting answer if it answered your original question ;) – G. Demecki Oct 21 '15 at 07:00
0

I have been chasing this problem for weeks. I'm using Wildfly 20, AdoptOpenJDK 14, Maven and MySql on MassiveGrid, a hosted server environment. What finally worked for me was a post I found on JBoss, which solved my problem. My test environment is Windows 10, which worked fine without the fix. The solution turned out to be adding a folder under Web Pages/META-INF named services and putting a file named java.sql.Driver with the following contents:

<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2010, Red Hat, Inc., and individual contributors
  ~ as indicated by the @author tags. See the copyright.txt file in the
  ~ distribution for a full listing of individual contributors.
  ~
  ~ This is free software; you can redistribute it and/or modify it
  ~ under the terms of the GNU Lesser General Public License as
  ~ published by the Free Software Foundation; either version 2.1 of
  ~ the License, or (at your option) any later version.
  ~
  ~ This software is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  ~ Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public
  ~ License along with this software; if not, write to the Free
  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  -->

<module xmlns="urn:jboss:module:1.0" name="com.mysql">
  <resources>
    <resource-root path="mysql-connector-java-8.0.18.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
  </dependencies>
</module>
Jim Reitz
  • 41
  • 3