Actually i am facing a problem calling a stored procedure and making some changes in the database in the same transaction. What i am doing is that i insert some data from en EJB (3.0) using jpql into an oracle database and than i call a stored procedure with a native jpa query to make some processing with the fresh data. But the problem is that the PL/SQL function doesn’t see changes unless i commit the transaction and than i make the call what i don’t want to do because i want to keep all changes in the same transaction. So the question is : is there any way to insert my data, call the pl/sql function and commit everything after that (or eventually roll back all changes) ?
thank you for your help
Make sure to call
entityManager.flush()before executing your stored procedure. Else, the persistence context might still have pending changes in memory. Flushing makes sure all the pending changes are written to the database.If that doesn’t work, then it means that the stored proc uses a different transaction than the one used by JPA.