hibernate 一对多的双向关联 查询异常

POJO:用户:privateStringfileid;privateUsersusers;privateStringfilename;privateStringfile... POJO:
用户:
private String fileid;
private Users users;
private String filename;
private String filesize;
private String fileuptime;
private Long isshare;
private String image;
xml配置:
<set name="fileses" inverse="true" cascade="all" lazy="false">
<key>
<column name="OID" />
</key>
<one-to-many class="com.wisoft.myapp.pojo.Files" />
</set>

POJO:
文件:
private String oid;
private String userid;
private String username;
private String password;
private Long isadmin;
private Set<Files> fileses = new HashSet(0);
xml配置:
<many-to-one name="users" class="com.wisoft.myapp.pojo.Users"

fetch="select" >
<column name="OID" />
</many-to-one>

查询:
public Files[] findFilesByUserId(String userid)
{
Object[] parms=new Object[1];
parms[0]=userid;
List<Files> lst =this.find("From Files as m where

m.users.oid =?",parms);
if(lst!=null&&lst.size()>0)
{
return lst.toArray(new Files[0]);
}
return null;
}

异常:
Hibernate: select files0_.FILEID as FILEID, files0_.FILENAME as

FILENAME1_, files0_.FILESIZE as FILESIZE1_, files0_.FILEUPTIME as

FILEUPTIME1_, files0_.ISSHARE as ISSHARE1_, files0_.IMAGE as IMAGE1_,

files0_.OID as OID1_ from SA.FILES files0_ where files0_.OID=?
2012-03-06 16:10:07,759-- ERROR -- could not initialize proxy - the

owning Session was closed -- [org.hibernate.LazyInitializationException]
org.hibernate.LazyInitializationException: could not initialize proxy -

the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize

(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation

(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept

(CGLIBLazyInitializer.java:134)
at

com.wisoft.myapp.pojo.Users$$EnhancerByCGLIB$$d75da000.getFileses

(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke

(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke

(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.xfire.aegis.type.basic.BeanType.readProperty

(BeanType.java:442)
at org.codehaus.xfire.aegis.type.basic.BeanType.writeObject

(BeanType.java:377)
at org.codehaus.xfire.aegis.type.basic.BeanType.writeObject

(BeanType.java:392)
at org.codehaus.xfire.aegis.type.basic.ArrayType.writeValue

(ArrayType.java:298)
at org.codehaus.xfire.aegis.type.basic.ArrayType.writeObject

(ArrayType.java:210)
at org.codehaus.xfire.aegis.AegisBindingProvider.writeParameter

(AegisBindingProvider.java:229)
at

org.codehaus.xfire.service.binding.AbstractBinding.writeParameter

(AbstractBinding.java:273)
at
展开
 我来答
我今天上课了
2012-03-06 · TA获得超过1410个赞
知道小有建树答主
回答量:844
采纳率:0%
帮助的人:677万
展开全部

LazyInitializationException,hibernate非常重要的两个异常之一,见图片

缘让我们相识D0a51
2012-03-08 · 超过18用户采纳过TA的回答
知道答主
回答量:84
采纳率:0%
帮助的人:57.3万
展开全部
你的查询函数返回了一个数据结构,你在主函数里面调用他?如果是这样,那么这样就不行了,因为这个对象已经处于脱管状态,需要设置他的惰性初始化
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友df1f619e4
2012-03-07
知道答主
回答量:53
采纳率:0%
帮助的人:26.7万
展开全部
List<Files> lst =this.find("From Files as m where m.users.oid =?",new Object[]{userid});
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ngexxejava
2012-03-06
知道答主
回答量:7
采纳率:0%
帮助的人:3万
展开全部
From Files as m where m.users.oid =?",parms
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式