I am new to Hibernate. While creating a small app using it I got following exception:
Exception in thread \"main\" java.lang.IllegalArgumentException: Unknown entit
Depends bit about project structure, but likely by adding following to persistence.xml directly under persistence-unit element.
<class>model.Students</class>
<class>model.Address</class>
Exactly like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="OneToOnePU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>students</jta-data-source>
<class>model.Students</class>
<class>model.Address</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-tables"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
<property name="hibernate.connection.username" value="app"/>
<property name="hibernate.connection.password" value="app"/>
<property name="hibernate.connection.url" value="jdbc:derby://localhost:1527/StudentsData"/>
</properties>
</persistence-unit>
</persistence>
By the way, why do you configure properties like hibernate.dialect in both persistence.xml and hibernate.cfg.xml?
How do you map your entities to the db tables? You can try using @Table(name="???") annotation with @Entity for this purpose, while ??? indicates the table name in the database for this entity.
I'm Trying this and it's working with me :
Add @EntityScan( basePackages = {"com.yourpkghere"}
to Application class.
To be like this :
@EntityScan( basePackages = {"com.yourpkghere"})
@SpringBootApplication