NamedPLSQLStoredFunctionQuery example not working [message #766192] |
Thu, 15 December 2011 10:46 |
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 09:26 |
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.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02330 seconds