[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] How to write entity into database using stored procedure?

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?

-- 
"Meaning is differential not referential"

kazik 'morisil' pogoda
http://www.xemantic.com/ http://blog.xemantic.com/