Menu

#4 HIGH_KEY table updates are not committed

open-later
None
5
2001-10-17
2001-10-10
No

UIDHighKeyGeneratorBean.java:
public Key getNextHighKey(Key theHighKey, String
theName):
You set con.setAutoCommit(false) and do not explicitly
commit() updates and inserts to HIGH_KEY table.

Discussion

  • Emmanuel Sciara

    Emmanuel Sciara - 2001-10-10
    • assigned_to: nobody --> sciara
     
  • Emmanuel Sciara

    Emmanuel Sciara - 2001-10-10

    Logged In: YES
    user_id=91163

    Are you stating this or did you actually try? If you tried,
    which plateform did you use?

     
  • Alexey Yudichev

    Alexey Yudichev - 2001-10-10

    Logged In: YES
    user_id=345880

    Sure I've tried. jBoss 2.4.1, MS SQL Server 7.0, Win2k.
    After putting con.commit() everything becomes ok. Else a
    duplicate key is generated by UIDDispenser.getDispenser
    ().getNextId().

     
  • Emmanuel Sciara

    Emmanuel Sciara - 2001-10-10

    Logged In: YES
    user_id=91163

    Hmmm, you are the second person to report a problem with
    JBoss 2.4.1 .

    Is the transaction of the stateless session bean still set
    the same way on JBoss 2.2 and 2.4? Because everything works
    fine on 2.2 and I wonder whether this is because the
    session is not set to create a new transaction when
    called...

    Emmanuel

     
  • Emmanuel Sciara

    Emmanuel Sciara - 2001-10-11

    Logged In: YES
    user_id=91163

    Ok I am suspecting more and more that this is a problem
    with the session not having the correct settings for its
    transaction.

    Here is the mail that David M. Karr, who has the same
    problem, sent to me. He is using user managed transaction
    to solve the problem. This is one valid solution but I
    would like to avoid that and have rather use container
    managed transaction.

    Unfortunately I won't be able to look into it until next
    week. Any comments?

    <Quote>

    Ok, here's what I did.

    I originally tried adding a "con.commit()" right before
    the "return()"
    statement, as the person who reported that bug "said" he
    did, although as you
    said, it wasn't clear whether he really did that or not.
    The effect of this
    change was zero. No change.

    Then, I instead added code at the beginning of the method
    to create a
    UserTransaction object, and called "begin()" on it. Right
    before the
    "return()", I called "commit()" on the UserTransaction
    object. This worked. I
    didn't do any more experimentation.

    This is the code I added to create the transaction:
    -------------------------
    UserTransaction transaction;
    try
    {
    transaction =
    (UserTransaction) ContextUtil.getInitContext().
    lookup("java:comp/UserTransaction");
    System.out.println("transaction[" + transaction
    + "]");
    transaction.begin();
    }
    catch (NamingException ex)
    {
    throw new RemoteException("Unable to find
    UserTransaction " +
    "java:comp/UserTransacti
    on", ex);
    }
    catch (NotSupportedException ex)
    { throw new RemoteException("Begin on
    UserTransaction failed", ex); }
    catch (SystemException ex)
    { throw new RemoteException("Begin on
    UserTransaction failed", ex); }
    -------------------------

    If you read section 11.6.1 of the EJB spec (which is the
    section mentioned in
    the error message), it does seem to allude to doing this,
    although it doesn't
    seem conclusive to me.

    I hope this helps.

    </quote>

     
  • Alexey Yudichev

    Alexey Yudichev - 2001-10-11

    Logged In: YES
    user_id=345880

    1) I have placed con.commit() in two places immediately
    after calls to ps.executeUpdate(). It works for sure.
    2) That time I just needed more to concentrate on the main
    business logic rather than on ejbUtils, that's why I had to
    find the simplest way. But as for container-managed
    transactions, I have no idea how jBoss manages transactions
    and why it doesn't commit() the connection obtained by the
    bean method with RequiresNew attribute.
    3) I am an EJB beginner :)

     
  • Emmanuel Sciara

    Emmanuel Sciara - 2001-10-12

    Logged In: YES
    user_id=91163

    Hereafter is the message I received from David. Could you
    please check that your transaction settings are correctly
    set to container, please. I will check later the 2 ejb-
    jar.xml files discussed below.

    <quote>
    Well, now I'm a bit confused. I had assumed that container-
    managed
    transactions would be preferred, but I thought I had seen
    that UIDDispenser was
    specifically set to bean-managed transactions. I'm not
    sure anymore how it was
    originally set. I was also confused about the difference
    between
    "$EJBUTILS_HOME/src/etc/ejb-jar.xml" and
    "$EJBUTILS_HOME/src/etc/DeployEJB/META-INF/ejb-jar.xml". I
    believe I had
    changed the former to "Container" quite a while ago, and I
    assumed that the
    build process copied the former to the latter, and then
    deployed that.

    Apparently, that was not the case. I just noticed that
    the "ejb-jar.xml" that
    was being deployed each time I tried to deploy it was still
    set to "Bean".

    So, I just tried removing my UserTransaction code, and made
    sure the bean was
    set to "Container", and I redeployed, and I found it worked
    fine.

    </quote>

     
  • Alexey Yudichev

    Alexey Yudichev - 2001-10-16

    Logged In: YES
    user_id=345880

    Yes, the problem is in transaction setting: Bean instead of
    Container. I was not attentive enough to check this before.

     
  • Emmanuel Sciara

    Emmanuel Sciara - 2001-10-17
    • status: open --> closed
     
  • Emmanuel Sciara

    Emmanuel Sciara - 2001-10-17

    Logged In: YES
    user_id=91163

    So, to summarise, the problem is due to the fact that the
    UIDHighKeyGenerator session bean has the wrong transaction
    setting: it is set to Bean instead of Container.

     
  • Emmanuel Sciara

    Emmanuel Sciara - 2001-10-17
    • status: closed --> open-later
     
  • Renaud Bruyeron

    Renaud Bruyeron - 2001-10-19

    Logged In: YES
    user_id=353988

    I have a similar problem with OrionServer 1.5.2.
    I set the Bean to have its transactions container managed,
    but I get large exceptions when running it. It looks like
    orion does not allow me to set the autoCommit mode in a
    <transaction-type>container</transaction-type> bean...
    the DB is oracle 8.1.6, I use the thin drivers. Here's what
    I see in the trace:

    creating new HighKey...
    groh, SQLE while creating
    java.sql.SQLException: calling setAutoCommit(true) is not
    allowed on a container-managed transactions Connection
    at com.evermind._wp.setAutoCommit(Unknown Source)
    at
    org.ejbutils.uid.UIDHighKeyGeneratorBean.getNextHighKey(UIDHighKeyGeneratorBean.java:251)
    at
    UIDHighKeyGenerator_StatelessSessionBeanWrapper2.getNextHighKey(UIDHighKeyGenerator_StatelessSessionBeanWrapper2.java:66)
    at
    org.ejbutils.uid.UIDDispenser.findNewHighKey(UIDDispenser.java:141)
    at org.ejbutils.uid.UIDDispenser.getNextId(UIDDispenser.java:87)
    at
    org.ejbutils.test.uid.UIDDispenserServerTestBean.doit(UIDDispenserServerTestBean.java:57)
    at
    UIDDispenserServerTest_StatelessSessionBeanWrapper4.doit(UIDDispenserServerTest_StatelessSessionBeanWrapper4.java:54)
    at
    __jspPage0_testKG_jsp._jspService(__jspPage0_testKG_jsp.java:40)
    at com.orionserver.http.OrionHttpJspPage.service(Unknown Source)
    at com.evermind._ah._rad(Unknown Source)
    at com.evermind.server.http.JSPServlet.service(Unknown Source)
    at com.evermind._cxb._abe(Unknown Source)
    at com.evermind._cxb._uec(Unknown Source)
    at com.evermind._io._twc(Unknown Source)
    at com.evermind._io._gc(Unknown Source)
    at com.evermind._if.run(Unknown Source)

    Dunno how to make it work so far (apart from using a
    UserTransaction).
    I will try more things monday.

     
  • Renaud Bruyeron

    Renaud Bruyeron - 2001-10-22

    Logged In: YES
    user_id=353988

    fixed the problem on orion1.5.2+oracle 8i by
    1) changing CHAR to VARCHAR in the ejbutils.sql
    2) commenting out the two lines that play with the
    connection's autocommit mode (setAutoCommit(boolean)).

     

Log in to post a comment.

MongoDB Logo MongoDB