请问各位大虾们, 在Hibernate中 ,ApplicationContext ap = new ClassPathXmlApplicationContext("applicationContext.xml");
SessionFactory sessionFactory = (SessionFactory)ap.getBean("sessionFactory");
Session session1 = sessionFactory.openSession();
与
Session session2 =
getHibernateTemplate().getSessionFactory().openSession();
session1与session2有何本质区别?
为什么我在数据库中写一个存储过程,通过session1就可执行,而session2却报一个 '找不到存储过程'的错误
SessionFactory sessionFactory = (SessionFactory)ap.getBean("sessionFactory");
Session session1 = sessionFactory.openSession();
与
Session session2 =
getHibernateTemplate().getSessionFactory().openSession();
session1与session2有何本质区别?
为什么我在数据库中写一个存储过程,通过session1就可执行,而session2却报一个 '找不到存储过程'的错误
解决方案 »
- 回车键问题
- Error dispatching bean action via URL pattern 。antlr-2.7.6.jar放到lib里了,重新部署了,不好用
- JSP(TOMCAT6.0)requesst.getParameter()中文乱码问题!!不是一般的郁闷!!
- jsp中的变量问题,请大虾帮忙,急!!
- 关于150G海量数据查询的问题(请大家给点思路)
- 足彩胜负彩的程序~~~~~~~~~~~(复式)
- 如何动态选择菜单(select)的值??
- javabean中从数据库提取varchar类型的数据,数据中如果是空串,提取出来的数据自动会加上一个空格?
- 写入数据时,出现程序(java.exe)错误,谁能帮我解决???
- 求助
- jsp的动态水印 【在线等】
- 函数为什么没有执行
再贴点配置或者代码,日志之类的看楼下的能不能帮到你 /**
* Set the Hibernate SessionFactory that should be used to create
* Hibernate Sessions.
*/
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
} /**
* Return the Hibernate SessionFactory that should be used to create
* Hibernate Sessions.
*/
public SessionFactory getSessionFactory() {
return this.sessionFactory;
}
getHibernateTemplate().getSessionFactory().openSession();获取session报了个 ‘存储过程’的错误,然后才用ApplicationContext ap = new ClassPathXmlApplicationContext("applicationContext.xml");这种方式的。在我看来似乎两种方式获取的session对象没啥区别啊,为什么通过getHibernateTemplate就不行呢?
必须在spring配置文件中为它注入SessionFactory
不然getHibernateTemplate()得到的HibernateTemplate里面的session是空的,
当然就抛出异常啦
public class PlaceManagerImpl extends HibernateDaoSupport implements PlaceManager
<bean id="placeManager" class="czw.business.manager.PlaceManagerImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
只要你启动web容器,session不应是空,再看看你的配置文件是否正确
而通过ApplicationContext ap = new ClassPathXmlApplicationContext("applicationContext.xml");获取的session调用存储过程则正常