Forums Register Login

Private Constructor, no error?

+Pie Number of slices to send: Send
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
e.g.


Can someone please explain why the code above behaves like this?
Thanks
1
+Pie Number of slices to send: Send
 

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.

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Yes, I haven't found any problem (yet) with the OpenJPA implementation.
This is my favorite show. And this is my favorite tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3012 times.
Similar Threads
persistence.xml file for MS SQL Server 2000
Problems With @ElementCollection
Value is session managed bean's attribute is nulled
javax.persistence.PersistenceException
Problem with refresh() method of EntityManamger in JPA
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:39:27.