Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
    Bookmark Topic Watch Topic
  • New Topic

hibernate Instantiation Exception: No default constructor, constructor problem

 
Pramod Kumar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Report post to moderator
Query q = em.createNamedQuery("User.byUserId");
q.setParameter("userId", userId);


--> user = (User) getSingleResult(q);

at this point I am getting following exception.
org.hibernate.InstantiationException: No default constructor for entity

Do I need to have a default constructor? Is it compulsory that do I need to have the default constructor?
Thanks,
Pramod.
---------------------
Your POJO needs a default, no args constructor. You don't need to define one unless you have define a constructor that takes arguments in you User class?

------------------------------------------------------


Thanks for the response below... I have 2 args construcotor in User class still I am getting this exception, once I keep the no arg constructor I didn't see this exception.

I am using enum for one colum and while inserting I am able to insert in to database while retreving I am getting the following exception.


Exception
------
No enum const class

Unknown name value for enum class com.UserRole: 0


------------------------------------------------


UserRole is an enum.

I am setting the values as

UserRole userRole = UserRole.DUSER;

and it is stored as 0 in database, while retreving I am getting the above exception.
 
    Bookmark Topic Watch Topic
  • New Topic