注册 登录
编程论坛 J2EE论坛

[求助]一个Hibernate问题

笑海 发布于 2007-05-13 08:36, 1514 次点击

usr.hbm.xml
<hibernate-mapping>
<class name="com.po.Usr" table="usr">
<id name="id" type="long">
<column name="id" />
<generator class="increment" />
</id>
<property name="name" type="string">
<column name="name" length="8" />
</property>
<property name="passwor" type="string">
<column name="passwor" length="8" />
</property>
<property name="phone" type="string">
<column name="phone" length="8" />
</property>
<property name="deptid" type="long">
<column name="deptid" />
</property>
<property name="address" type="string">
<column name="address" length="32" />
</property>
<property name="title" type="string">
<column name="title" length="16" />
</property>
<property name="power" type="string">
<column name="power" length="16" />
</property>
<property name="auth" type="string">
<column name="auth" length="16" />
</property>
<property name="homephone" type="string">
<column name="homephone" length="8" />
</property>
<property name="superauth" type="string">
<column name="superauth" length="4" />
</property>
<property name="groupid" type="long">
<column name="groupid" />
</property>
<property name="birthdate" type="date">
<column name="birthdate" length="10" />
</property>
<property name="male" type="string">
<column name="male" length="4" />
</property>
<property name="email" type="string">
<column name="email" length="128" />
</property>
</class>
</hibernate-mapping>
我的调用程序
import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import com.po.*;


public class manager {
public void getList(){

Session session = null;
HibSession hib = new HibSession();
try{

session = hib.getSession();
Query query = session.createQuery("from Usr where id=36047");
List list = query.list();
Iterator it = list.iterator();
while(it.hasNext()){
Usr usr = (Usr) it.next();
System.out.println("name=="+usr.getName());
}
}catch(Exception e){
e.printStackTrace();

}
}

public static void main(String[] args) {
manager ma = new manager();
ma.getList();
我的异常

org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.po.Usr.setGroupid
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:203)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.bo.manager.getList(manager.java:20)
at com.bo.manager.main(manager.java:34)
Caused by: net.sf.cglib.beans.BulkBeanException
at com.po.Usr$$BulkBeanByCGLIB$$499efc80.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
... 14 more
Caused by: java.lang.NullPointerException
... 16 more


请问我哪错了 帮忙 谢谢

11 回复
#2
davidah2007-05-13 10:36

问题可能出在你的pojo上,只看异常
"org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.po.Usr.setGroupid"
好象是你的映射文件和pojo上的设置不一致!!你在检查检查!!!

#3
hardes2007-05-13 12:47
是不是JavaBean的属性类型跟Hibernate的映射类型的问题哦!!
映射出错了!你检查看看!!


#4
笑海2007-05-13 15:35

应该怎么改 我还是不大清楚

#5
hardes2007-05-14 14:54
因该怎么改?
这问题问得,程序员不仅仅是要你怎么写代码,我发现很多写程序的都不知道该怎么调试自己出错的程序!!
你可以先写个简单的JavaBean啊,属性就都设置一些基本的数据类型.先调试下看看啦!!

#6
黄袖标2007-05-14 15:46

少jar包...把rar改成jar,不过我怀疑你还少别的jar...少了再发帖子吧

只有本站会员才能查看附件,请 登录

#7
笑海2007-05-16 23:17

谢谢 我先去试试吧

#8
笑海2007-05-16 23:28
在问问 在用Hibernate3.0的时候 应该加些什么jar包

我在用3.0时候 总是报错 我想应该是少了一些包
#9
独孤无痕2007-05-17 16:49
spring+hibernate
#10
想你的天空2007-05-20 00:29
LOG4J跟踪下
#11
pizilai2007-05-21 20:55
欢迎加入QQ群:39720980 (J2EE 群)
#12
笑海2007-05-22 22:21
已经解决 是少包啊 谢谢各位
1