timcoat (3) [Avatar] Offline
#1
I have implemented the jms and scheduled-tasks as outlined in Chapter 10.5 and beyond.

I attempted to add an additional operation. I tried to use a Domain Entity finder method in the ScheduledProcessor process() method. The problem I am getting the following error:

org.hibernate.SessionException: Session is closed!; nested exception is javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed!

What is the proper way to setup and use Domain Entitys inside of the ScheduledProcessor process() method?
timcoat (3) [Avatar] Offline
#2
Re: JMS scheduled-tasks Domain
Take a look at this:

http://stackoverflow.com/questions/5375197/using-a-dao-on-a-bean-used-by-a-spring-scheduled-task

This solved my problem.

However, I am still interested in what people here have to say.
ken.rimple (246) [Avatar] Offline
#3
Re: JMS scheduled-tasks Domain
Tim,

Hmm... I think your problem is that you're not running under the context of a user, therefore the automatic transaction management process wouldn't necessarily run.

I agree, you probably can't use a transactional queue without a transaction, so creating one sounds like it makes sense.

Ken
bbaron (61) [Avatar] Offline
#4
Re: JMS scheduled-tasks Domain
Keep in mind that transaction boundaries do not propagate across threads. I ran into this the other day where I was using @Async to invoke a method in a background thread. (I wanted the ability to timeout if the method didn't return in 30 seconds). The calling method had a readOnly transaction in progress (to fetch data to pass to the Async method). The Async method was annotated with a read-write enabled transaction. In a test, I used a SyncTaskExecutor which executes everything in a single thread. An exception was thrown when a db update occurred in the read only transaction. This served to remind me that the Async method didn't inherit the caller's transaction until I configured it to run synchronously.