Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
    Bookmark Topic Watch Topic
  • New Topic

hibernate Instantiation Exception: No default constructor, constructor problem  RSS feed

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?
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.

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
Boost this thread!