Pages

Wednesday, March 09, 2011

"java.lang.IllegalArgumentException: Unknown entity" and "org.hibernate.MappingException: Unknown entity:"

I got this exception during using hibernet with MySQL. This is a very simple error. Just you need to add the entity class name in persistence.xml file as follows (marked red). In fact most of the IDEs will provide you a GUI for doing 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="SimpleTestPU" transaction-type="RESOURCE_LOCAL">

    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <class>yourPackage.yourEntity </class>

    <properties>

      <property name="hibernate.connection.username" value="root"/>

      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>

      <property name="hibernate.connection.password" value="blah blah "/>

      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/da2642e0 "/>

      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>

    </properties>

  </persistence-unit>

</persistence>

 

No comments:

Post a Comment