Skip to main content


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 10:46 Go to next message
Luis Perez is currently offline Luis PerezFriend
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 Go to previous messageGo to next message
Luis Perez is currently offline Luis PerezFriend
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 19:34 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
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 19:35 Go to previous messageGo to next message
James is currently offline JamesFriend
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/
Re: NamedPLSQLStoredFunctionQuery example not working [message #1744923 is a reply to message #768224] Sun, 02 October 2016 23:59 Go to previous message
graeme kitchen is currently offline graeme kitchenFriend
Messages: 5
Registered: September 2016
Junior Member
I needed to add
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
to my persistmnce.xml

Also in the example fname gets set twice in the package body Smile
Previous Topic:Nested REF_CURSOR
Next Topic:EciplseLink Caching - Strange behaviour
Goto Forum:
  


Current Time: Tue Mar 19 11:50:11 GMT 2024

Powered by FUDForum. Page generated in 0.02330 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top