How to write entity into database using stored procedure? [message #381069] |
Tue, 02 September 2008 08:37 |
Kazimierz Pogoda 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:
<code>
@Entity
@NamedStoredProcedureQueries({
@NamedStoredProcedureQuery(
name="Book.getBook",
procedureName="TEST.GET_BOOK",
resultClass=Book.class,
parameters={
@StoredProcedureParameter(queryParameter="ID",
direction=Direction.IN_OUT),
@StoredProcedureParameter(queryParameter="TITLE",
direction=Direction.OUT)}),
@NamedStoredProcedureQuery(
name="Book.listBooks",
procedureName="TEST.LIST_BOOKS",
resultClass=Book.class,
parameters={@StoredProcedureParameter(queryParameter="OUTPUT ",
direction=Direction.OUT_CURSOR)})
})
public class Book implements Serializable {
@Id
private Long id;
private String title;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
</code>
After having such entity it is just enough to call:
Query query = em.createNamedQuery("Book.getBook");
query.setParameter("ID", 10);
Book book = query.getSingleResult();
or
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?
|
|
|
|
Powered by
FUDForum. Page generated in 0.04128 seconds