Forum Stats

  • 3,826,733 Users
  • 2,260,699 Discussions
  • 7,897,065 Comments

Discussions

best practice to call procedure & function from database inside entity (ex : Doml method)

Hello,

1-what's the best practice to call database procedure and function in entity Impl ?

i made the procedure call inside Application module like (    DBTransaction trx = (DBTransaction) getTransaction();

    CallableStatement st = null;

    try {

      String stmt = "begin my_procedure_name (?); end;";

      st = trx.createCallableStatement(stmt, 0);

      st.setObject(1, param);

      st.executeUpdate();

    } )

then call it inside the entity impl using ( ESAppModuleImpl am =(ESAppModuleImpl) Configuration.createRootApplicationModule

am.mymethod_name

)

this is the best practice for my case ?

thanks in advance.

my jdev ver. : 12.2.1.2.0

Best Answers

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 38,458 Red Diamond

    No, you should never use (or try to never use) createRootApplicationModule.

    The EntityObject has a method getDBTransaction() to get the transaction without the need to go through a root application module. If you need the application module you can get it via the method DBTransaction like

    DBTransaction tx = ...
    ApplicationModule am = tx.getRootApplicationModule();
    

    Timo

    Abdelrahman ElGiar
  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 38,458 Red Diamond

    You can do the calculation in java and put it in a base class. Then you only have to call the base class and set the value wherever you like.

    If you have t do it in the DB, you can use triggers (so it's done inside the DB).

    As the last resort, I would do the function/procedre call inside the EO.


    Timo

    Abdelrahman ElGiar

Answers