Why is persistence unit named null when persistence.xml exists
A couple of possible issues:
- Incorrect location of the
persistence.xml
file. Please place it insideMETA-INF/
directory at the root of the archive. If you use maven it would besrc/main/resources/META-INF/persistence.xml
. - Invalid
persistence.xml
file: you havepersistence-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>