1. 程式人生 > >Spring data jpa 呼叫儲存過程

Spring data jpa 呼叫儲存過程

1,先保證升級相關的類庫

<org.springframework-version>4.1.7.RELEASE</org.springframework-version>

<spring.data.jpa.version>1.9.6.RELEASE</spring.data.jpa.version>

<org.hibernate-version>5.0.8.Final</org.hibernate-version>

2,create stored procedure

PROCEDURE xxSearch_member(xPara in nvarchar2, xcur_ret out nvarchar2) is

  xkey1                 varchar2(100);
  xkey2                 varchar2(100);
  xname                 varchar2(100);
begin

    xkey1 := xxXml_child_text(xPara,'key1');
    xkey2 := xxXml_child_text(xPara,'key2');
    xName := xxXml_child_text(xPara,'name');
   
   xcur_ret :='<users><user><userId>1</userId><userName>Tom</userName></user><user><userId>2</userId><userName>Jos</userName></user></users>';

end xxSearch_member;

3,修改PO

@Entity
@Table(name="W_USER")
@NamedQuery(name="UserId.findAll", query="SELECT u FROM UserId u")

@NamedStoredProcedureQueries(value = {
    @NamedStoredProcedureQuery(name="UserId.searchMember", procedureName = "TRAN_PROC.xxSearch_member",parameters = {
        @StoredProcedureParameter(mode = ParameterMode.IN, type = String.class),
        @StoredProcedureParameter(mode = ParameterMode.OUT, type = String.class) })

,
@NamedStoredProcedureQuery(name = "UserId.testPro", procedureName = "TRAN_PROC.testPro", parameters = {
        @StoredProcedureParameter(mode = ParameterMode.IN, type = Integer.class),
        @StoredProcedureParameter(mode = ParameterMode.OUT, type = Integer.class)
})
})

public class UserId implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;