[英]How to check if Hibernate is using a database index while loading data
[英]error while loading data from table using hibernate
我正在使用hibernate作為ORM工具,並在從表中加載數據時,我收到以下錯誤。
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
請讓我知道,我想念的是什么......
下面是我的班級
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;
}
}
和hbm文件如下:
<?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>
我的猜測是你的HotelUser
類上沒有非私有的,默認的(無參數)構造函數。
檢查POJO類中的(默認)非參數構造函數。 如果沒有,請再次插入和編譯
我最近也遇到了同樣的問題......
這與在Web應用程序的類路徑中擁有多個版本的cglib jar文件有關。 雖然我不確定它是否是這個jar文件,或者hibernate使用和依賴的任何其他jar文件,因為我在其他版本的類路徑中也有其余的hibernate jar文件。
通過刪除cglib和其他jar的沖突版本,事情再次起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.