wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Unknown entity error in Hibernate during session.saveOrUpdate() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Unknown entity error in Hibernate during session.saveOrUpdate()" Watch "Unknown entity error in Hibernate during session.saveOrUpdate()" New topic
Author

Unknown entity error in Hibernate during session.saveOrUpdate()

achsu subra
Greenhorn

Joined: Feb 01, 2011
Posts: 11
Hi All,

I am trying to save data using session.saveOrUpdate(obj). Here obj is a bean object and is returned by calling a method from a class that is in another jar. The bean class is also defined in this jar file.

For e.g in below Market.hbm.xml file, the Market bean is in the jar file and the package points to the jar. In MktPersistance.java, the below error is thrown at saveOrUpdate(). Looks like Market class is not being identified since its in the jar file. Also, the values in obj object are displaying correctly logger.info("\nEntity to be persisted=" + obj).

14:37:01.345 [pool-1-thread-1] ERROR c.a.f.n.o.s.support.MktPersistence - Unknown entity: com.pnd.data.Market

Please let me know how this can be resolved. Thanks a lot for your time.




Thanks a lot in advance..
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Shouldn't the package be 'com.pnd.data'?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
achsu subra
Greenhorn

Joined: Feb 01, 2011
Posts: 11
Wouter Oet wrote:Shouldn't the package be 'com.pnd.data'?


Hi Wouter,

Thanks for your reply.
Sorry, the package is 'com.pnd.data', I had mistyped it. The same error is still thrown.
Please let me know in case of any suggestions.
Waswani Naresh
Ranch Hand

Joined: May 01, 2008
Posts: 66
Have you included/mentioned the hbm mapping file in the hibernate config file (hibernate.cfg.xml).

Something like this :

<mapping resource="com/pnd/data/Market.hbm.xml" />

Regards,
Naresh Waswani


Naresh Waswani
Andrew Kessel
Greenhorn

Joined: Aug 16, 2011
Posts: 5
If you use JPA entities, you must mention your entity in "hibernate.cfg.xml" that way:
<hibernate-configuration>
<session-factory>
...
<mapping class="com.pnd.data.Market" />
</session-factory>
</hibernate-configuration>


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unknown entity error in Hibernate during session.saveOrUpdate()