I have a project and I'm having trouble configuring it to work with JPA and hibernate.
I have a class with the @Entity
annotation, and when I try to persist an instance of it, I get this error:
java.lang.IllegalArgumentException: Unknown entity: com.package.to.MyEntityClass
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1149)
... (stack trace of my code trying to persist an instance built from a request to a servlet)
Apparently Hibernate can't see that MyEntityClass
is supposed to be an entity.
However if I add <class>
elements to my persistence.xml
file, the entity can be found, and I get errors that its @OneToOne
annotation references an unknown entity, which I'm assuming I also need to add to the persistence.xml file.
Aren't classes with @Entity
annotations supposed to be discovered automatically? I looked at this question and I tried to reference my .war file in the <jar-file>
tag as it recommends but it didn't work. (I get a file not found exception)
Any idea how I can fix this? I'm using JBoss EAP 7 to deploy, and this is my persistence.xml
:
<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="unit1" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/OracleDS</jta-data-source>
<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.Oracle10gDialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<!-- Configuring Connection Pool -->
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="10" />
<property name="hibernate.c3p0.timeout" value="500" />
<property name="hibernate.c3p0.max_statements" value="30" />
<property name="hibernate.c3p0.idle_test_period" value="2000" />
</properties>
</persistence-unit>
</persistence>