急!十万火急!!!

psq824696660 2017-07-24 11:28:39
这是异常

Struts has detected an unhandled exception:

Messages:
could not initialize proxy - no Session
Error reading 'nameCn' on type entity.Position_$$_javassist_5
An exception occurred processing JSP page /WEB-INF/page/index.jsp at line 33 30: 31:
32:${employee.position.nameCn}
Stacktrace:
File: org/hibernate/proxy/AbstractLazyInitializer.java
Line number: 132

下面是代码

public String toIndex(){
employee = (Employee)ActionContext.getContext().getSession().get("employee");
return "toIndex";
}
public String login(){
employee = ls.queryLogin(employee);
if(employee!=null){
ActionContext.getContext().getSession().put("employee", employee);
return "reIndex";
}
return "toLogin";
}

然后是配置

<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>

求大佬帮忙
...全文
236 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
李德胜1995 2017-07-24
  • 打赏
  • 举报
回复
关于懒加载的问题,在employee = ls.queryLogin(employee);下面加上一句Hibernate.initialize(employee.getPostion());即可。。。
psq824696660 2017-07-24
  • 打赏
  • 举报
回复
引用 4 楼 aschouas 的回复:
[quote=引用 2 楼 psq824696660 的回复:] [quote=引用 1 楼 aschouas 的回复:] ${employee.position.nameCn} nameCn 写错了吧
这是JAVA BEAN

public class Employee 
	private String sn;
	private Position position;
	private Department department;
	private String name;
	private String password;
	private String status;

public class Position
	private Integer id;
	private String nameCn;
	private String nameEn;
	private Set employees = new HashSet(0);
[/quote] 一对多映射的配置贴出来[/quote]

Employee.hbm.xml

<many-to-one name="position" class="entity.Position" fetch="select">
            <column name="POSITION_ID" >
                <comment>职位ID</comment>
            </column>
        </many-to-one>

Position.hbm.xml

  <set name="employees" inverse="true">
            <key>
                <column name="POSITION_ID" >
                    <comment>职位ID</comment>
                </column>
            </key>
            <one-to-many class="entity.Employee" />
        </set>
psq824696660 2017-07-24
  • 打赏
  • 举报
回复
引用 3 楼 zc881124 的回复:
你这一对多的隐射关系,从数据取出来的时候,Position是不是没取出来 你在后台打印下。
我这个是重定向跳转,改成转发的时候是可以出来的 但是SESSION跟重定向没关系啊,所以搞不清什么意思
一个治疗术 2017-07-24
  • 打赏
  • 举报
回复
引用 2 楼 psq824696660 的回复:
[quote=引用 1 楼 aschouas 的回复:] ${employee.position.nameCn} nameCn 写错了吧
这是JAVA BEAN

public class Employee 
	private String sn;
	private Position position;
	private Department department;
	private String name;
	private String password;
	private String status;

public class Position
	private Integer id;
	private String nameCn;
	private String nameEn;
	private Set employees = new HashSet(0);
[/quote] 一对多映射的配置贴出来
110成成 2017-07-24
  • 打赏
  • 举报
回复
你这一对多的隐射关系,从数据取出来的时候,Position是不是没取出来 你在后台打印下。
psq824696660 2017-07-24
  • 打赏
  • 举报
回复
引用 1 楼 aschouas 的回复:
${employee.position.nameCn} nameCn 写错了吧
这是JAVA BEAN

public class Employee 
	private String sn;
	private Position position;
	private Department department;
	private String name;
	private String password;
	private String status;

public class Position
	private Integer id;
	private String nameCn;
	private String nameEn;
	private Set employees = new HashSet(0);
一个治疗术 2017-07-24
  • 打赏
  • 举报
回复
${employee.position.nameCn} nameCn 写错了吧

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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