• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stored procedure and JPA

 
Ravi Danum
Ranch Hand
Posts: 154
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Does anyone have a code sample of how to call a stored procedure using JPA (Toplink)?

The stored procedure only needs to return an error code.

Thanks in advance.

Ravi
 
Ravi Danum
Ranch Hand
Posts: 154
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone answer this?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TopLink 11g / EclipseLink support a NamedStoredProcedureQuery annotation for defining named stored procedure queries:

http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Extensions_for_Stored_Procedure_Query

You can also execute stored procedures dynamically. You can use the StoredProcedureCall object in the org.eclipse.persistence.queries package with a DatabaseQuery, such as a DataReadQuery. You can execute the DatabaseQuery through the EclipseLink EntityManager interface JpaEntityManager or JpaQuery.
 
Ravi Danum
Ranch Hand
Posts: 154
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.

Would you recommend putting the call to the stored procedure in the persist method of the JPA entity bean (for example Customer entity class)? Also, EclipseLink hasn't made it into NetBeans as far as I know, but I will look.

-Ravi
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no specific way given to call store procedure in the JPA and as you asked calling in persist method doesn't sounds correct so the solutions you have are you can either call it with native query as:



or some database support it to be called as prepared statements so you have use that route.

Thanks,
Rahul
 
Ravi Danum
Ranch Hand
Posts: 154
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Rahul.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic