Alfred’s Computing Weblog

Alfred Java-cored Computing Weblog

No Hibernate Session bound to thread

with one comment

Problem:
I hit an error “No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here” while I’m doing unit testing in an application that combining Spring Batch and Hibernate. This problem exists when I try to do some data insertion at the Spring Batch Listener.

Solution:
The root of this problem occurred is because there is NO hibernate session at the Spring Batch Listener level. How come?!?! Its because the AOP pointcut I defined and use throughout the application is at the Batch JobRepository
<aop:config>
<aop:advisor pointcut="execution(* org.springframework.batch.core..*Repository+.*(..))"
advice-ref="txAdvice" />
</aop:config>

But the Batch Listener is not under the same / child package of the JobRepository. The Listener is under org.springframework.batch.core.StepExecutionListener. To ease the configuration, I add in another pointcut at my business package my.com.company.project.writer.MyItemWriter.beforeStep.
The AOP pointcut I added is:
<aop:config>
<aop:advisor pointcut="execution(* my.com.pv.batch.report.writer.CdrItemWriter.beforeStep(..))"
advice-ref="txAdvice" />
</aop:config>

Lessons Learned:
1. Identified where is the point cuts, is that the existing pointcut is enough for me?

Advertisements

Written by Alfred

April 23, 2008 at 10:40

Posted in Java

Tagged with , , ,

One Response

Subscribe to comments with RSS.

  1. Man .. Beautiful .. Wonderful .. I will bookmark your site and take the feeds alsoI am satisfied to search out numerous helpful information right here within the publish, we need work out more strategies in this regard, thanks for sharing. . . . . .

    Proornomoting

    September 25, 2011 at 11:01


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: