It's mentioned in the JPA spec 2_0 that an entity must have a no-arg constructor and it should be public or protected. I changed the visibility to private and everything(persistence logic) works fine. I am able to save and retrieve object without any warning/error. Why so? I am using Mysql and hibernate 4.3-6.Final as JPA provider. The same goes for final class , i made my Entity final and it still works.
But if i call clear() method on em , and perform some action on entity then i get Runtime exception related with private constructor
Can someone please explain why the code above behaves like this?
I changed the visibility to private and everything(persistence logic) works fine. I am able to save and retrieve object without any warning/error. Why so?
That means that your JPA implementation is not obeing the JPA specifications (by the way: hibernate 4.3-x is JPA 2.1)
I created a small example and tested it with the openjpa implementation and I got the expected error:
Exception in thread "main" <openjpa-2.3.0-r422266:1540826 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: [Error while processing persistent type nl.notes.jpa.Person, declared in \nl\notes\jpa\Person.java. Error details: Unenhanced classes must have a public or protected no-args constructor. Type nl.notes.jpa.Person's no-args constructor is private or package-visible.
posted 5 years ago
Thanks, for exam purpose should i use openJPA 2.0 as an implementation in order to get the same behavior as mentioned in JPA specification?