Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to write entity into database using stored procedure?
How to write entity into database using stored procedure? [message #381069] Tue, 02 September 2008 08:37 Go to next message
Kazimierz Pogoda is currently offline Kazimierz PogodaFriend
Messages: 1
Registered: July 2009
Junior Member
Originally I posted this message on eclipselink-users mailing list, but I
have no answer so far thus I am posting it here hoping to get some help.

I can read entities using stored procedures perfectly:

parameters={@StoredProcedureParameter(queryParameter="OUTPUT ",

public class Book implements Serializable {

private Long id;

private String title;

public Long getId() {
return id;
public void setId(Long id) { = id;
public String getTitle() {
return title;
public void setTitle(String title) {
this.title = title;

After having such entity it is just enough to call:

Query query = em.createNamedQuery("Book.getBook");
query.setParameter("ID", 10);
Book book = query.getSingleResult();


Query query = em.createNamedQuery("Book.listBooks");
List<Question> books = query.getResultList();

Now I want to do the opposite - somehow pass the entity as stored
procedure input.

I imagine it could be done either by using a bunch of IN parameters
corresponding to entity fields (but then how to set them automatically
without using explicit query.setParameter calls), or rather by using
some automatic mapping of entity into java.sql.Struct which is then
passed as single stored procedure argument. I tried to configure it
without any success. Any ideas?
Re: How to write entity into database using stored procedure? [message #381073 is a reply to message #381069] Tue, 02 September 2008 14:04 Go to previous message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
You can override the EclipseLink insert/update/delete operations to use
stores procedures. There are not currently annotations for this (please
log or vote for this issue), but you can do it through a
DescriptorCustomizer. You use the ClassDescriptor getQueryManager() and
use the StoredProcedureCall class and setInsertCall() API. Then you just
need to persist the object, and your procedure will be called.

You could also define a named query with a bunch of IN parameters to
perform the insert, and pass all of the object's attributes manually, but
this would be treated as a data only operation.

-- James
Previous Topic:Roadmap for EclipseLink 1.1
Next Topic:Where to post feature proposals?
Goto Forum:

Current Time: Mon Jun 25 10:30:57 GMT 2018

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

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

Back to the top