Spring / Hibernate / JUnit - No Hibernate Session bound to Thread
http://stackoverflow.com/questions/734614/spring-hibernate-junit-no-hibernate-session-bound-to-thread
Wrong, that will just fill your code with session management code.
First, add a transaction management bean in your context:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean>
The second thing, extend AbstractTransactionalJUnit4SpringContextTests
public class BaseDALTest extends AbstractTransactionalJUnit4SpringContextTests{
Third thing, annotate you test class with
@TransactionConfiguration @Transactional
If your transaction demarcation is correct(surrounding your dao or service) you should be done.
It's not nice to sprinkle session and transaction handling code all around your code (even inside your tests).
相关推荐
shirleypaddy 2020-10-19
qingmumu 2020-10-19
lustdevil 2020-10-18
ganlulululu 2020-10-12
lustdevil 2020-08-03
lustdevil 2020-07-18
lustdevil 2020-06-25
lustdevil 2020-06-21
zhengzf0 2020-06-21
宿命java 2020-06-15
JackYin 2020-06-14
dongxurr 2020-06-07
snowphy 2020-06-06
zhengzf0 2020-05-28
81901836 2020-05-26
Julywhj 2020-05-26