can SQL statement issued by JDBC call see changes made by CMP ?

Discussions

EJB programming & troubleshooting: can SQL statement issued by JDBC call see changes made by CMP ?

  1. Hi all

    It would be very thankful somebody can help to answer my below question.

    i have a transaction, within which CMP are used to update some records and then a oracle stored procedure is called to do bulk update / lookup operations. The stored procedures have to see the changes made by CMP in order to correctly execute. As far as i know, WL 8.1 will optimized CMP data access by combining multiple setter calls to a single update statement and issue that SQL statement to DB at the end of tx (by default, delay-update-until-end-of-tx is true). But as i know, invocation of finder method will lead to flush of changes to DB. I have 2 questions about this behaviour

    1) within the same tx, if CMP A and CMP B is called for update and then CMP B's finder method is called. Will both changes made through A & B be flushed to DB ? or Only CMP B's changes will be flushed ? or only CMP involved in that SQL will be flushed ?

    2) As stated above, if within same tx, a mix of CMP and direct JDBC call are made, will the stored procedure called through JDBC see those changes made through CMP if delay-update-until-end-of-tx must be kept true for performance benefit. If not so, any recommendation on workaround ?

    thank u very much in advance.
    dso
  2. Hi!

    This is a very complicated problem. I recommend you to read section 17.7 in the EJB 2.1 spec., and expecially section 17.5.5. You problem is not mentioned in the spec., but I think you will see how complicated your problem is.

    Honestly, I recommend you to try another design. The reason is that this is one of the few points where the EJB spec. is a bit unclear. Solutions will depend on the implementation of the container.

    /Tomas
  3. Hi all

    >
    > It would be very thankful somebody can help to answer my below question.
    >
    > i have a transaction, within which CMP are used to update some records and then a oracle stored procedure is called to do bulk update / lookup operations. The stored procedures have to see the changes made by CMP in order to correctly execute. As far as i know, WL 8.1 will optimized CMP data access by combining multiple setter calls to a single update statement and issue that SQL statement to DB at the end of tx (by default, delay-update-until-end-of-tx is true). But as i know, invocation of finder method will lead to flush of changes to DB. I have 2 questions about this behaviour
    >
    > 1) within the same tx, if CMP A and CMP B is called for update and then CMP B's finder method is called. Will both changes made through A & B be flushed to DB ? or Only CMP B's changes will be flushed ? or only CMP involved in that SQL will be flushed ?
    >
    > 2) As stated above, if within same tx, a mix of CMP and direct JDBC call are made, will the stored procedure called through JDBC see those changes made through CMP if delay-update-until-end-of-tx must be kept true for performance benefit. If not so, any recommendation on workaround ?
    >
    > thank u very much in advance.
    > dso

    In reference to 1: Only the CMP involved in that SQL will be flushed. Until then the changes would only be made in memory, and the container would wait till the end of the txn to flush those changes

    In reference to 2: The stored procedure will not see those changes, because those changes are not yet flushed. If for any reason, you cannot change your design, then I would recommend issuing a finder method call to flush your changes before the stored proc is invoked.
    If you have more than one persistence mechanism for your business objects, (CMP and Direct JDBC) I would be very careful in the usage of entity beans, especially around the issue of optimistic locking.

    Thanks
    DS