0

I have a stored procedure in an Oracle DB, which I wish to call from my EJB AS (websphere) using the following JPA code. The procedure includes some "COMMIT" in its body. The point is that when I remove the COMMIT of the procedure, JPA is able to invoque the procedure correctly. If I leave the COMMIT then I get an exception telling me that the call cannot be executed.

The java code is placed in a session bean with the transaction set up as REQUIRED by default.

    public void updateProc() {
       Query query = entityManager.createNativeQuery("call UPDATE_MYPROC()");
       query.executeUpdate();
    }

I think the problem has to do with the transaction, but not sure. Can anybody help? Thanks!

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
narko
  • 3,645
  • 1
  • 28
  • 33

1 Answers1

3

You are using the container to manage persistence. By using transaction REQUIRED, JPA will start a new transaction for each call to the database. Therefore it's not necessary to start or commit a transaction within the stored procedure. In fact, it's a bad idea.

You don't mention if you start a new transaction in the stored procedure, just that you have a commit in there. If you don't start a (new) transaction, that commit will cause problems. Even if you do, it's unnecessary, this is the sort of stuff we use JPA for to start with.

WPrecht
  • 1,340
  • 1
  • 17
  • 29