-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: org.hibernate.InstantiationException:
PostPosted: Fri Nov 09, 2012 12:55 pm 
Newbie

Joined: Fri Nov 09, 2012 12:29 pm
Posts: 1
Hi, im trying to create an SpringMVC+hibernate+MySQL Annotation aplication, and getting this exception:
(The "app" are to protect personal info.)

org.hibernate.InstantiationException: No default constructor for entity: com.app.spsce.Models.TblUsers

TblUsers its a auto-generated class by hibernate tools with eclipse plugin, the constructor its in. Why, hibernate cant locate it?, and some one knows how to solve or evade this issue?


Class/model TblUsers:

Code:
package com.app.spsce.Models;

import java.io.Serializable;
import javax.persistence.*;
// Generated 06-nov-2012 8:37:57 by Hibernate Tools 3.4.0.CR1
/**
* TblUsers generated by hbm2java
*/
@Entity
@Table(name = "tbl_users", catalog = "consumo_electrico_dev")
public class TblUsers implements Serializable {

   
   private static final long serialVersionUID = -9192394099078208460L;
   
   private int id;
   private String user;
   private String pass;
   private String nombre;

   
   /**
    * ************************************************************
    */
        public TblUsers() {
      
   }

   public TblUsers(int id) {
      this.id = id;
   }

   public TblUsers(int id, String user, String pass, String nombre) {
      this.id = id;
      this.user = user;
      this.pass = pass;
      this.nombre = nombre;
   }
   @Id
   @Column(name = "id", unique = true, nullable = false)
   public int getId() {
      return this.id;
   }

   public void setId(int id) {
      this.id = id;
   }

   @Column(name = "User", length = 70)
   public String getUser() {
      return this.user;
   }

   public void setUser(String user) {
      this.user = user;
   }

   @Column(name = "Pass", length = 30)
   public String getPass() {
      return this.pass;
   }

   public void setPass(String pass) {
      this.pass = pass;
   }

   @Column(name = "Nombre", length = 250)
   public String getNombre() {
      return this.nombre;
   }

   public void setNombre(String nombre) {
      this.nombre = nombre;
   }

   @Override
   public int hashCode() {
      // TODO Auto-generated method stub
      return super.hashCode();
   }

   @Override
   public boolean equals(Object obj) {
      // TODO Auto-generated method stub
      return super.equals(obj);
   }

   @Override
   protected Object clone() throws CloneNotSupportedException {
      // TODO Auto-generated method stub
      return super.clone();
   }

   @Override
   public String toString() {
      // TODO Auto-generated method stub
      return super.toString();
   }

   @Override
   protected void finalize() throws Throwable {
      // TODO Auto-generated method stub
      super.finalize();
   }

}


Mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 06-nov-2012 8:37:57 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="Models.TblUsers" table="tbl_users" catalog="consumo_electrico_dev">
        <id name="id" type="int">
            <column name="id" />
            <generator class="assigned" />
        </id>
        <property name="user" type="string">
            <column name="User" length="70" />
        </property>
        <property name="pass" type="string">
            <column name="Pass" length="30" />
        </property>
        <property name="nombre" type="string">
            <column name="Nombre" length="250" />
        </property>
    </class>
</hibernate-mapping>


DB info: table name in DB is tbl_users, hibernate tools create TblUsers for default.

Controller Calls Service:
Code:
private UsersService usersService;
...
..
List<TblUsers>  users= usersService.getAllUsers();
...


Service:
Code:
package com.app.spsce.Services;

import java.util.List;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.app.spsce.Models.TblUsers;

@Service("usersService")
@Transactional
public class UsersService {
protected static Logger log = Logger.getLogger("Service");
   
@Resource(name="sessionFactory")
private SessionFactory sessionFactory;

public List<TblUsers> getAllUsers(){
try{
   log.debug("Retrieving all users");
   TblUsers tu = new TblUsers() ;
   
   Session session = sessionFactory.getCurrentSession();
   Query query = session.createQuery("FROM tbl_users");
   return query.list();
}catch(Exception ex){
    log.debug(ex.getMessage());
   
   return null;
}
}
}


I got Exception on "ex" from line of Query query = session.createQuery("FROM tbl_users");
if i Change the line to Query query = session.createQuery("FROM TblUsers");

still getting same exception.


Thanks, for you time


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.