3

i am using hibernate as ORM tool, and while loading the data from table i am getting following error.

org.hibernate.HibernateException: CGLIB Enhancement failed: com.hotel.entity.HotelUser
    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:96)
    at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.getProxy(CGLIBProxyFactory.java:49)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:379)
    at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3455)
    at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:257)
    at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:191)
    at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
    at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
    at org.hibernate.impl.SessionImpl.load(SessionImpl.java:795)
    at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788)
    at com.hotel.domain.UserLoginService.checkUserCredentials(UserLoginService.java:17)
    at com.hotel.app.UserLoginManager.checkUserCredentials(UserLoginManager.java:12)
    at com.hotel.app.UserLoginManager.main(UserLoginManager.java:23)
Caused by: java.lang.InstantiationException: com.hotel.entity.HotelUser$$EnhancerByCGLIB$$fa712a57
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyInstance(CGLIBLazyInitializer.java:107)
    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:93)
    ... 12 more

please let me know, what i am missing...

below is my class

public class HotelUser implements Serializable {

    private static final long serialVersionUID = 1L;
    private String userId;
    private String password;
    private String userName;

    private HotelUser() {

    }
    /**
     * @param userId
     * @param password
     * @param userName
     * @param lastLoginDate
     */
    public HotelUser(String userId, String password, String userName) {
        super();
        this.userId = userId;
        this.password = password;
        this.userName = userName;
    }
    /**
     * @return the userId
     */
    public String getUserId() {
        return userId;
    }
    /**
     * @param userId the userId to set
     */
    public void setUserId(String userId) {
        this.userId = userId;
    }
    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }
    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
    /**
     * @return the userName
     */
    public String getUserName() {
        return userName;
    }
    /**
     * @param userName the userName to set
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }
}

and the hbm file is below :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.hotel.entity.HotelUser" table="hotel_user">
        <id name="userId" type="string" column="USER_ID">
        </id>
        <property name="password" type="string" column="PASSWORD" />
        <property name="userName" type="string" column="USER_NAME" />
    </class>
</hibernate-mapping>
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
M.J.
  • 16,266
  • 28
  • 75
  • 97

3 Answers3

10

My guess is that you don't have a non-private, default (no-arg) constructor on your HotelUser class.

See this question for more details.

Community
  • 1
  • 1
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 1
    thanks .. that worked i added default constructor and that ran without any problem.. but if i dont want to have a default constructor, then what to do?? – M.J. Nov 13 '10 at 09:41
  • @Mrityunjay you can't. See the link I added – Bozho Nov 13 '10 at 09:54
0

check for (default)non-argument constructor in POJO class. if not there , insert and compile again

0

I recently faced with the same issue too….

It was something to do with having more than one version of the cglib jar file in the web app's class path. Though I am not sure if it is this jar file, or any of the other jar files that hibernate uses and depends on, as I also had the rest of the hibernate jar files in the class path in a different version.

By removing conflicting versions of the cglib & other jars, things worked again.

Swapna
  • 2,245
  • 2
  • 19
  • 22