Buy anything from HongKong - Dealextreme

You can buy any kind of electronic gadgets from DealExtreme with free shipping option.
Please visit DealExtreme for very low prices.
Here is the link to the site : www.dealextreme.com

25 November 2008

Procedure call with hibernate and JPA

Suppose we have the following procedure :

create or replace procedure

insertTown(res out sys_refcursor, str in string)

as

begin

insert into town values(10000,81,str);

open res for select count(*) as toplam from town;

end insertTown;


Create a native query on one of the entities :

@NamedNativeQuery(name = "insertTown", resultSetMapping = "MyResults", query = "{call insertTown(?,:VAR)}", hints = {

@QueryHint(name = "org.hibernate.callable", value = "true"),

@QueryHint(name = "org.hibernate.readOnly", value = "false") })

@SqlResultSetMapping(name = "MyResults", columns = { @ColumnResult(name = "toplam") })

public class UserAuditLog implements java.io.Serializable {

...


And call the procedure in a transactional context :

BigDecimal i = (BigDecimal)em.createNamedQuery("insertTown")

.setParameter("VAR", "deneme")

.getResultList().get(0);

No comments: