1

couldn't find any kind of relevant information besides useless tutorials on the internet as well as in the specs.

There's one thing that I struggle with right now, if you can please help.

Here's the thing.

lets say we have two EJB version 3.0 with annotations about their transaction type, one is bean managed ( let it be BeanManaged ) second is container managed ( let it be ContainerManaged, how creative ).

Then this happens:

@TransactionBlahBlah(Type.BEAN)
class BeanManaged {

   @Inject
   private ContainerManaged contMngt; // here's the implicit container managed trnsactional bean ( not annotated or anything )

    void someMethod() {
         // some transaction creation and a bit of inserts and updates      
        contMngt.callingMethodThatIsGoingToCreateContainerManagedTransaction();

         // some batches that are inserts
        for( int y = 0 ; y < 100 ; y++ ) {
             for( int i = 100 ; i < 200 ; i ++ ) {
                    magicPreparedStatementOutOfNowhere.setParameter(666, "hell");
                    magicPreparedStatementOutOfNowhere.addBatch();
             }
             magicPreparedStatementOutOfNowhere.executeBatch();
        }
        transaction.commit(); // let's pretend it is not here
    }
}

What is going on in the mechanics of it all, does the bean managed transaction becomes some kind of 'orphaned' container managed transaction? Do they mix? How do they interact if at all? Does one transaction separates from the other

That's my deduction but, there's something more to that.

At the end when I try to commit the bean transaction it says " hello sir, this transaction is managed, and it is forbidden to commit it manually " with SQLException as desert.

Then there's the thing with batches, that i collect somehow. After 100 batches added I want to execute them, but only the last one is executed actually, seems like addBatch does not work at all.

Anybody can relate, or met something similar is welcomed, every wizard gets free cookies.

sheeva
  • 11
  • 3

1 Answers1

0

What TransactionAttribute do you have specified on the container-managed bean? I would suggest Mandatory. With Mandatory the container will not start transactions for you. Instead it will protect your bean by ensuring it cannot be called unless a transaction is in progress.

This related question has some useful information as well.

Community
  • 1
  • 1
Ryan
  • 2,058
  • 1
  • 15
  • 29
  • actually there's none, which by default means container managed transaction with required. I did sovle my problem already, however I am still puzzled when it comes to understand how JDBC works. The batches that didn't went into the driver were deleted in the same transaction later in code somehow very implicitly( by delete query ) , that was the deal, but they didn't even reached the JDBC output ( they were truncated by the driver ) does the JDBC driver implementation optimizes the network overheat by ignoring the inserts when there's delete afterwards? – sheeva Apr 20 '15 at 15:21