Search code examples
oracle-databasehibernatejpaejbfire-and-forget

A way to not wait for JPA query result in EJB


i want to know if is there a way to not wait for JPA query result in ejb i have to call a stored procedure whit JPA that make some mass complex treatements on Oracle database, i found javax.ejb.Asynchronous but i don't want to create a thead for that, just call and forget the sotred procedure

Thnaks


Solution

  • The JDBC API that JPA is typically based on is synchronous, so you cannot achieve what you want without creating a secondary thread to wait for JDBC to return. One alternative would be creating a helper stored procedure in Oracle that just schedules execution of the main stored procedure and returns immediately. Then you would invoke the helper stored procedure from Java.

    Sort of:

    create or replace procedure schedule_myjob is
    begin
        -- search documentation for 
        dbms_job.submit('myjob', ....);
        -- NOTE: dbms_job.submit will not have effect until you commit
        -- your transaction. 
    end schedule_myjob;
    
    create or replace procedure myjob is
    begin
       -- Your main procedure code
       ...
    end myjob;