DAO中要用getCurrentSession来获得session的话,spring中hibernate4.LocalSessionFactoryBean需要怎么配
我DAO中注入了sessionFactory要用getCurrentSession老是报NoSessionfoundforcurrentthread用opensessio...
我DAO中注入了sessionFactory要用getCurrentSession老是报No Session found for current thread
用opensession在第一次用没问题,再用会报Illegal attempt to associate a collection with two open sessions,是不是没关闭session的原因?如果要用getCurrentSession我需要怎么配置呢?
不会排版,大家凑合看看吧
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan" value="blog/model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">
update
</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>blog.model.Blog</value>
<value>blog.model.Comment</value>
</list>
</property>
<property name="dataSource" ref="dataSource"></property>
</bean> 展开
用opensession在第一次用没问题,再用会报Illegal attempt to associate a collection with two open sessions,是不是没关闭session的原因?如果要用getCurrentSession我需要怎么配置呢?
不会排版,大家凑合看看吧
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan" value="blog/model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">
update
</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>blog.model.Blog</value>
<value>blog.model.Comment</value>
</list>
</property>
<property name="dataSource" ref="dataSource"></property>
</bean> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询