1

I have below method to save an object to database using Hibernate but I keep getting "org.hibernate.MappingException: Unknown entity: java.lang.Class" error while saving.

System.out.println("transientInstance:" + transientInstance);
System.out.println("transientInstance:" + transientInstance.getClass());  
getSession().save(transientInstance);  

System.out.println statements are printing below information.
transientInstance:class com.mypkg.pojo.Details
transientInstance:class java.lang.Class

Any idea what could be wrong please?

Thanks,

1
  • Can you incldue the com.mypkg.pojo.Details class - especially any association to other classes. Commented May 20, 2012 at 17:03

1 Answer 1

3

You're trying to store a java.lang.Class object, rather than an entity instance. transientInstance is not an entity instance. It's com.mypkg.pojo.Details.class.

The error is in code that you don't show, before the call to save().

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry but I didn't get what it means the "error is before the call to save()". Any idea on how I can fix this?
It makes no sense to call getSession().save(Details.class). Find where Details.class is passed as argument to this method, and fix the bug by passing the object rather than its class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.