Two Laptop Bag*
The moose likes Object Relational Mapping and the fly likes eclipselink stored procedures with result returned from different tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "eclipselink stored procedures with result returned from different tables" Watch "eclipselink stored procedures with result returned from different tables" New topic
Author

eclipselink stored procedures with result returned from different tables

Rene Ummels
Greenhorn

Joined: Feb 12, 2010
Posts: 11
Hi,

Will the book explain how to handle stored procedures? Some scenarios, for instance with EclipseLink and a mix of tables in the returned result.

We have made some stored procedure code, the result from the stored procedure containing a mix of two tables (destinationNumber from ported; networkRoutingPrefix from network).
Is the below way correct and efficient?










thanks,
Rene
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Not sure what book you are referring to.

Your stored procedure call seems ok. Although odd that you define it using annotations as a named query, but then create a new call to execute it. You could just use the named query (although if your call works, it seems your procedure returns a result-set not output parameters).

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
Hi Rene,

We have tried to keep the book vendor-neutral and focused on the specification itself, and since stored procedures are not defined in the spec we did not include them. However, they are on my feature list for the JPA 2.1 specification, so there is a good chance they will be in the next edition of the book.

As James mentioned, since you are defining a named query you might want to stick with that and keep the vendor-specific code out of your method.


-Mike
Pro JPA 2: Mastering the Java Persistence API
Rene Ummels
Greenhorn

Joined: Feb 12, 2010
Posts: 11
Hi,

Good feedback. So, if I understand you correctly this would mean to change the code as follows, right?




kind regards,
Rene
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
There is no @ in the JPA query parameter name. It is just the name that you specified as the queryParameter when you defined the query, which was portedNumber.
Rene Ummels
Greenhorn

Joined: Feb 12, 2010
Posts: 11
Thanks Mike.
I now substituted:

by:


Then I executed the createNamedQuery() code but I get an exception:
Caused by: java.lang.IllegalArgumentException: NamedQuery of name: ported.p_sel_number_info not found.
How can I solve this?


thanks,
Rene
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
Hi Rene,

Your entity manager should be from the EMF of the same persistence unit as the Result entity or the query name won't be in that namespace. If you think that is okay in your app then you might want to go through the EclipseLink forums for more specific help. They are pretty helpful there.
Rene Ummels
Greenhorn

Joined: Feb 12, 2010
Posts: 11
Hi,

The actual solution was to update the sybase stored procedure from:

to:


In this way, the columns were mapped correctly.


br,
Rene
 
Consider Paul's rocket mass heater.
 
subject: eclipselink stored procedures with result returned from different tables
 
Similar Threads
JPA and StoredProcedureCall
output parameter from stored procedure: Operand type clash: VARCHAR is incompatible with VOID Type
call a stored procedure using eclipselink Problem...
Calling Stored Procedure thru JPA
stored procedure exception (primary key null)