I use JAVA SE and Hibernate. I have a package with annotated class name Message (with javax @Entity annotation). my persistence.xml is very simple:
<?xml version="1.0" encoding="UTF-8"?>
<persistence-unit
name="myFirstJPA"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL10Dialect"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/testdb"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.password" value="mypassword"/>
</properties>
</persistence-unit>
As far as I know Hibernate scans all the annotated class at startup in order to use them with entityManager. So when I want to persist simple entity via entitymanager.persist I get an error of type IllegalArgumentException: Unknown entity
only when I add the following to persistence.xml
<class>com.example.entity.Message</class>
The exception goes away and everything works fine.
Since I have approximately 100 entities in my project I don't want to add each one of them to the persistence.xml file I want to Hibernate to detect them automatically. Any ideas?