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 展开
用户:
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 展开
4个回答
展开全部
你的查询函数返回了一个数据结构,你在主函数里面调用他?如果是这样,那么这样就不行了,因为这个对象已经处于脱管状态,需要设置他的惰性初始化
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
List<Files> lst =this.find("From Files as m where m.users.oid =?",new Object[]{userid});
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
From Files as m where m.users.oid =?",parms
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询