views:

33

answers:

1

We have container transaction with Spring and JPA (Hibernate). I need to make an update on a table to "flag" some rows via native statements. Then we insert some rows via EntityManager from JPATemplate to this table. After that, we need to calculate changes in the table via native statement (with Oracle's union and minus, complex groups...)

I see that changes from step 1 and 2 are not commited and thats why the statement from 3 fails. I already tried with transaction propagation REQUIRES_NEW, EntityManager.flush... Didn't work.

1) update SOMETABLE acolumn = somevalue (native)
2) persist some values into SOMETABLE (via entity manager)
3) select values from SOMETABLE

Is there a possibility to read the changes from step 1 and 2 in step 3?

+1  A: 

I guess you are using the same DataSource in the JpaTransactionManager, JdbcTemplate and JpaTemplate and have enabled @Transactional with this:

<tx:annotation-driven />

Assuming it is not a configuration bug, my best guess is that you're calling on the @Transactional method from a method in the same class?

In that case, you need AspectJ to weave in the transaction logic or refactor the code so the @Transactional method is in another class than the calling method. (The refactor option is the easy and preferred one)

If this doesn't solve your problem, you should add the relevant classes to your question together with relevant log messages.

Espen