hibernate+spring myeclipse小记
来源:互联网 发布:篮网数据 编辑:程序博客网 时间:2024/05/19 19:13
最近困恼了几天的东西终于搞出来了。用junit进行测试DAO类(PermissionDaoHibernateImpl),问题就一步一步清晰了。把碰到的主要问题记下:
PermissionDaoHibernateImpl代码如下:
public class PermissionDaoHibernateImpl extends HibernateDaoSupport
implements PermissionDao {
//查询一个用户的权限,放在一个列表中,用于填充页面上的树型菜单
public List<Permission> findUserPermission(final String userId){
Session session = getSessionFactory().openSession();
List<Permission> result = null;
try{
final String sSql =" select permission.* from permission where ID in"
+" (select distinct permissionID from rolepermission where roleID=:uId )";
//将查询出来的一个用户的所有的权限放入一个列表中
List<Permission> list1 = (List<Permission>) session.createSQLQuery(sSql)
.addEntity("permission", Permission.class)
.setString("uId", userId).list();
List<Permission> result1=list1;
//返回权限列表
return result1;
}
catch(RuntimeException ex){
System.out.println("chaxunquanxianchucuo"+ex);
return result;
}
}
}
抛出的问题:
1>junit.framework.AssertionFailedError: Exception in constructor: testFindUserPermission (org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [F:/JSF代码/ch24/ch24/rbac/WebRoot/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
.....
由于lib下包的问题,由于有些包在WEB-INF/lib下,没有显示在referenced liberaries下。(正常情况下myeclipse中相关的到到入到WEB-INF/lib,且这个包有用,则这个包会显示在referenced liberaries下,lib下就不显示了)。解决办法:重新建立一个WEB工程,再全部导入。
2>org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean$TransactionAwareInvocationHandler.invoke(AbstractSessionFactoryBean.java:299)
at $Proxy0.getCurrentSession(Unknown Source)
at com.jsfabc.jsh.model.dao.hibernateImpl.PermissionDaoHibernateImpl.findUserPermission(PermissionDaoHibernateImpl.java:16)
at com.jsfabc.jsh.model.dao.hibernateImpl.PermissionDaoImptest.testFindUserPermission(PermissionDaoImptest.java:23)
.....
由于开始代码中写成了 Session session = sessionFactory.getCurrentSession()。
应该写为Session session = getSessionFactory().openSession();
由于session是已经有了的,就不用再创建了。
2008/7/25日
PermissionDaoHibernateImpl代码如下:
public class PermissionDaoHibernateImpl extends HibernateDaoSupport
implements PermissionDao {
//查询一个用户的权限,放在一个列表中,用于填充页面上的树型菜单
public List<Permission> findUserPermission(final String userId){
Session session = getSessionFactory().openSession();
List<Permission> result = null;
try{
final String sSql =" select permission.* from permission where ID in"
+" (select distinct permissionID from rolepermission where roleID=:uId )";
//将查询出来的一个用户的所有的权限放入一个列表中
List<Permission> list1 = (List<Permission>) session.createSQLQuery(sSql)
.addEntity("permission", Permission.class)
.setString("uId", userId).list();
List<Permission> result1=list1;
//返回权限列表
return result1;
}
catch(RuntimeException ex){
System.out.println("chaxunquanxianchucuo"+ex);
return result;
}
}
}
抛出的问题:
1>junit.framework.AssertionFailedError: Exception in constructor: testFindUserPermission (org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [F:/JSF代码/ch24/ch24/rbac/WebRoot/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
.....
由于lib下包的问题,由于有些包在WEB-INF/lib下,没有显示在referenced liberaries下。(正常情况下myeclipse中相关的到到入到WEB-INF/lib,且这个包有用,则这个包会显示在referenced liberaries下,lib下就不显示了)。解决办法:重新建立一个WEB工程,再全部导入。
2>org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean$TransactionAwareInvocationHandler.invoke(AbstractSessionFactoryBean.java:299)
at $Proxy0.getCurrentSession(Unknown Source)
at com.jsfabc.jsh.model.dao.hibernateImpl.PermissionDaoHibernateImpl.findUserPermission(PermissionDaoHibernateImpl.java:16)
at com.jsfabc.jsh.model.dao.hibernateImpl.PermissionDaoImptest.testFindUserPermission(PermissionDaoImptest.java:23)
.....
由于开始代码中写成了 Session session = sessionFactory.getCurrentSession()。
应该写为Session session = getSessionFactory().openSession();
由于session是已经有了的,就不用再创建了。
2008/7/25日
- hibernate+spring myeclipse小记
- Myeclipse开发struts+hibernate+spring小记
- myeclipse hibernate spring整合开发
- MyEclipse配置struts+hibernate+spring
- MyEclipse配置struts+hibernate+spring
- 使用MyEclipse开发Spring+Hibernate
- MyEclipse Spring Hibernate整合开发
- myEclipse struct2+spring+hibernate配置
- MyEclipse Spring Hibernate整合开发
- MyEclipse搭建spring MVC+Hibernate
- SpringData,Spring与Hibernate整合小记
- jdk+tomcat+myeclipse+spring开发环境配置小记
- hibernate小记
- hibernate 小记
- hibernate小记
- hibernate 小记
- Hibernate小记
- 图解MyEclipse配置struts+hibernate+spring+FreeMarker
- ShellExecute
- JS运算符
- dll的分类
- vbs调用ActiveX的DLL的方法
- Linux:VI 替换命令
- hibernate+spring myeclipse小记
- 设计模式之 Template
- 进制转换
- 一个软件工程师的六年心得
- Extjs实现confirm对话框
- 用vbscript实现将脚本的输出复制到剪贴板
- 调用Win32 API netapi32.dll 实现UNC(网络共享)连接的管理(一)
- 如何确定正在运行脚本的文件夹的路径?
- CSS使用技巧