Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Exception calling an Oracle Stored Procedure

Hi Jose

Can you add the following statement after creating the session object.

    session.setLogLevel(SessionLog.FINEST);


Then you can observe what is going on behind the scenes.

Which tool are you using to manage your database and why does it not let you query the table?
Can you confirm if you are using the right credentials to invoke the stored procedure?

Thanks
Rohit

On 3/24/2011 1:37 PM, Jose Alvarez de Lara wrote:
Hi,
 
I have done some changes in the code. It leaves as follows,
 
...the specification

CREATE OR REPLACE PACKAGE RECORD_SET
AS
type cursorType is ref cursor;
Procedure COUNTRIES_LIST(p_region IN NUMBER, p_ResultSet out cursorType);
END RECORD_SET ;

...and the body

CREATE OR REPLACE PACKAGE BODY RECORD_SET ISPROCEDURE COUNTRIES_LIST
(
p_region IN NUMBER,
p_ResultSet out cursorType
) IS

BEGIN

OPEN p_ResultSet FOR SELECT country_name, country_id, region_id
FROM countries
WHERE region_id = p_region;

EXCEPTION

When NO_DATA_FOUND then
dbms_output.put_line('No hay datos');

END;

END RECORD_SET ;

And the java code,

 public List<RecordDetail> getCountriesSP(BigDecimal region) throws Exception {

     EntityManagerFactory emf = Persistence.createEntityManagerFactory("OracleStoredProcedureCalling-jpa");
     EntityManager em = emf.createEntityManager();
     
     List<RecordDetail> list = null;
     try {
      
      JpaEntityManager jpaEntityManager = JpaHelper.getEntityManager(em);
      Session session = jpaEntityManager.getActiveSession();
      StoredProcedureCall call = new StoredProcedureCall();
      call.setProcedureName("HR.RECORD_SET.COUNTRIES_LIST");
      call.addNamedArgument("P_REGION", "REGION_ID", BigDecimal.class);
      call.useNamedCursorOutputAsResultSet("P_RESULTSET");
      
      DataReadQuery query = new DataReadQuery();
      query.setCall(call);
      query.addArgument("P_REGION");
 
      List queryArgs = new ArrayList();
      queryArgs.add(region);
     
      List results = (List) session.executeQuery(query, queryArgs);
      
      list = new ArrayList<RecordDetail>();
      for(int i=0; i<results.size(); i++){
       DatabaseRecord record = (DatabaseRecord) results.get(i);
       String name = (String)record.get("country_name");
       String id = (String)record.get("country_id");
       RecordDetail rd = new RecordDetail(name, id);
       list.add(rd); 
      }

      return list;
                 
     } catch (Exception ex) {
      throw ex;
     }

     finally {
      em.close();
     }
    }

But it returns an empty List, and the database table in the schema HR has many records.

It is possible that it be a question of privileges?, the tool I use to manage the database does not let me
query the table.

Thanks.

 

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies

Back to the top