Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NamedPLSQLStoredFunctionQuery example not working
NamedPLSQLStoredFunctionQuery example not working [message #766192] Thu, 15 December 2011 05:46 Go to next message
Luis Perez is currently offline Luis Perez
Messages: 4
Registered: December 2011
Junior Member
Hi,

I'm using the following tools:
Eclipselink 2.3.2.v20111125-r10461
JPA 2.0.3.v201010191057
NetBeans 7.1RC2
Java JDK 1.6_27 (64 bits)
Oracle JDBC Driver 11.2.0.20

I'm trying the examples in this page:

"http:||wiki.eclipse.org|EclipseLink|Examples|JPA|PLSQLStoredFunction"

I've set up the Oracle objects in a new/fresh schema.

When I try this pice of code (see the page above):
import javax.persistence.Query;
import org.eclipse.persistence.platform.database.orcle.plsql.PLSQLStoredFunctionCall;
import org.eclipse.persistence.queries.ReadAllQuery;
 
DataReadQuery databaseQuery = new DataReadQuery();
PLSQLrecord record = new PLSQLrecord();
record.setTypeName("EMP_PKG.EMP_REC");
record.setCompatibleType("EMP_TYPE");
record.setJavaType(Employee.class);
record.addField("F_NAME", JDBCTypes.VARCHAR_TYPE, 30);
record.addField("L_NAME", JDBCTypes.VARCHAR_TYPE, 30);
record.addField("SALARY", JDBCTypes.NUMERIC_TYPE, 10, 2);
PLSQLStoredFunctionCall call = new PLSQLStoredFunctionCall(record);
call.setProcedureName("EMP_PKG.GET_EMP");
databaseQuery.setCall(call);
 
Query query = ((JpaEntityManager)entityManager.getDelegate()).createQuery(databaseQuery);
Employee result = (Employee)query.getSingleResult();


I get this error:
java.lang.ClassCastException: org.eclipse.persistence.sessions.DatabaseRecord cannot be cast to Employee

I've seen that the code execute the funtion and retrive an oracle.sql.STRUCT object, but not the Employee object.

Also, if I try the annotated version (usin a named query), like this:

Query query = entityManager.createNamedQuery("getEmployee");
Employee result = (Employee)query.getSingleResult();


I'm getting this error:

java.lang.IllegalArgumentException: NamedQuery of name: getEmployee not found.

Perhaps I'm missing something in the setup. Any help is always welcome.

Thanks in advance,
Luis
Re: NamedPLSQLStoredFunctionQuery example not working [message #766699 is a reply to message #766192] Fri, 16 December 2011 04:26 Go to previous messageGo to next message
Luis Perez is currently offline Luis Perez
Messages: 4
Registered: December 2011
Junior Member
Hi again,

follow-up:

I moved the code
@PLSQLRecord(name="EMP_PKG.EMP_REC", compatibleType="EMP_TYPE", javaType=Employee.class,
fields={@PLSQLParameter(name="F_NAME"), @PLSQLParameter(name="L_NAME"), @PLSQLParameter(name="SALARY", databaseType="NUMERIC_TYPE")})
@NamedPLSQLStoredFunctionQuery(name="getEmployee", functionName="EMP_PKG.GET_EMP",
returnParameter=@PLSQLParameter(name="RESULT", databaseType="EMP_PKG.EMP_REC"))


to an @Entity and now the call to the Named Query "getEmployee" it's working (there is an issue with the returned value not correctly constructed but I must investigate further).

The api call it's still failing.

Thanks in advance for any advise,
Luis.
Re: NamedPLSQLStoredFunctionQuery example not working [message #768222 is a reply to message #766699] Mon, 19 December 2011 14:34 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

For the class cast you are probably getting a row (Map) back with an Employee in it.
You be able to set,

databaseQuery.setResultType(DataReadQuery.VALUE);

to fix the issue.


James : Wiki : Book : Blog : Twitter
Re: NamedPLSQLStoredFunctionQuery example not working [message #768224 is a reply to message #766699] Mon, 19 December 2011 14:35 Go to previous message
James is currently offline James
Messages: 272
Registered: July 2009
Senior Member
For the class cast you are probably getting a row (Map) back with an Employee in it.
You be able to set,

databaseQuery.setResultType(DataReadQuery.VALUE);

to fix the issue.
--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Previous Topic:EclipseLink Cache Coordination with Oracle GoldenGate
Next Topic:ClassNotFoundException on EclipseLink MOXy
Goto Forum:
  


Current Time: Fri Aug 01 18:33:20 EDT 2014

Powered by FUDForum. Page generated in 0.04992 seconds