could not initialize proxy - no Session

xiajunsuc 2010-05-26 09:03:40
08:37:15,203 ERROR LazyInitializationException:19 - could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at com.bjsxt.oa.model.Orgnization$$EnhancerByCGLIB$$8b056ba1.getParent(<generated>)
at com.bjsxt.oa.web.actions.OrgAction.execute(OrgAction.java:64)
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:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
...全文
72 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiajunsuc 2010-05-26
  • 打赏
  • 举报
回复
<hibernate-mapping>
<class table="t_orgnization" name="com.bjsxt.oa.model.Orgnization">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="sn"/>
<property name="description"/>

<many-to-one column="pid" name="parent" fetch="join"/>
<set lazy="false" inverse="true" name="children">
<key column="pid"/>
<one-to-many class="com.bjsxt.oa.model.Orgnization" />
</set>
</class>
</hibernate-mapping>
好像也不行呀
archko 2010-05-26
  • 打赏
  • 举报
回复
getParent你设置了False是Children的有什么用.
<many-to-one column="pid" name="parent" />加一个fetch="select或join"
xiajunsuc 2010-05-26
  • 打赏
  • 举报
回复
lazy 已经设置成false,配置如下:

<hibernate-mapping>
<class table="t_orgnization" name="com.bjsxt.oa.model.Orgnization">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="sn"/>
<property name="description"/>

<many-to-one column="pid" name="parent" />
<set lazy="false" inverse="true" name="children">
<key column="pid"/>
<one-to-many class="com.bjsxt.oa.model.Orgnization" />
</set>
</class>
</hibernate-mapping>

package com.bjsxt.oa.model;

import java.util.Set;

/**
*
* @author Administrator
* @hibernate.class table="T_Orgnization"
*/
public class Orgnization {

private int id;

private String name;

private String sn;
private String description;

private Orgnization parent;

private Set children;

private int parentId =0;

public int getParentId() {
return parentId;
}

public void setParentId(int parentId) {
this.parentId = parentId;
}

public Set getChildren() {
return children;
}
public void setChildren(Set children) {
this.children = children;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Orgnization getParent() {
return parent;
}
public void setParent(Orgnization parent) {
this.parent = parent;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
}

if(parentId != 0){
Orgnization org = orgManager.findOrg(parentId);
Orgnization parent = org.getParent();(执行这句开始出错)
if(parent != null){
ppid = parent.getId();
}
}
equest.put("ppid", ppid);
izard999 2010-05-26
  • 打赏
  • 举报
回复
延迟加载的问题.. 把set中的lazy设成false
  • 打赏
  • 举报
回复
需要看你的ssh配置文件才能下结论
archko 2010-05-26
  • 打赏
  • 举报
回复
<many-to-one column="pid" name="parent" fetch="join" lazy="false"/>这样写后日志里记录的SQL是怎样的,有没有把Parent查出来呢?
没办法就加个过滤器,HibernateFilter,在一个Request里控制Session
xiajunsuc 2010-05-26
  • 打赏
  • 举报
回复
如何配置事务
sl514 2010-05-26
  • 打赏
  • 举报
回复
事务配置
sl514 2010-05-26
  • 打赏
  • 举报
回复
事物配置出了问题
xiajunsuc 2010-05-26
  • 打赏
  • 举报
回复
hibernate-mapping>
<class table="t_orgnization" name="com.bjsxt.oa.model.Orgnization">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="sn"/>
<property name="description"/>

<many-to-one column="pid" name="parent" />
<set lazy="false" inverse="true" name="children">
<key column="pid"/>
<one-to-many class="com.bjsxt.oa.model.Orgnization" />
</set>
</class>
</hibernate-mapping>

package com.bjsxt.oa.model;
import java.util.Set;
public class Orgnization {

private int id;

private String name;

private String sn;
private String description;

private Orgnization parent;

private Set children;

}

if(parentId != 0){
Orgnization org = orgManager.findOrg(parentId);
Orgnization parent = org.getParent();(执行这句开始出错)
if(parent != null){
ppid = parent.getId();
}
}
request.put("ppid", ppid);
zz250121244 2010-05-26
  • 打赏
  • 举报
回复
no session 说明你的session已经关闭了.才导致了你的懒加载错误. 你是ssh一起用报的错还是怎么的?配置文件都贴出来啊. 光贴一个hibernate的配置文件能说明问题吗.
xiajunsuc 2010-05-26
  • 打赏
  • 举报
回复
按照上面的配置也不行
xiajunsuc 2010-05-26
  • 打赏
  • 举报
回复
<hibernate-mapping>
<class table="t_orgnization" name="com.bjsxt.oa.model.Orgnization">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="sn"/>
<property name="description"/>

<many-to-one column="pid" name="parent" fetch="join" lazy="false"/>
<set lazy="false" inverse="true" name="children">
<key column="pid"/>
<one-to-many class="com.bjsxt.oa.model.Orgnization" />
</set>
</class>
</hibernate-mapping>
archko 2010-05-26
  • 打赏
  • 举报
回复
不会吧.再加个lazy="false" 试试

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧