Gas*_*ton 8 java stored-procedures hibernate criteria
这是我的问题,我必须使用一个大的SP,并且没有时间在java中重写.所以我正在使用Hibernate标准,我不知道我是否可以调用它.谢谢大家.
请参阅参考文档中的使用存储过程进行查询.
映射查询就像这样调用.
List employment = sess.getNamedQuery("BigSP")
.list();
Run Code Online (Sandbox Code Playgroud)
映射查询可以返回实体.
<sql-query name="BigSP" callable="true">
<return alias="emp" class="Employment">
<return-property name="employee" column="EMPLOYEE"/>
<return-property name="employer" column="EMPLOYER"/>
<return-property name="startDate" column="STARTDATE"/>
<return-property name="endDate" column="ENDDATE"/>
<return-property name="regionCode" column="REGIONCODE"/>
<return-property name="id" column="EID"/>
<return-property name="salary">
<return-column name="VALUE"/>
<return-column name="CURRENCY"/>
</return-property>
</return>
{ call BigSP }
</sql-query>
Run Code Online (Sandbox Code Playgroud)
不,您需要使用本机查询.如果您使用的是注释,请参阅2.3.2.映射本机查询.
下面是一个例子:
@Entity
@NamedNativeQuery(
name="baz",
query="call fooProc(:bar, :i)",
callable=true,
readOnly=true,
resultClass=Foo.class
)
public class Foo {
private Date when;
//...
}
Run Code Online (Sandbox Code Playgroud)
并称之为:
@Stateless
public class FooBean implements FooLocal {
@PersistenceContext EntityManager em;
public Foo getAFoo(string bar, int i) {
Foo result = (Foo)em.createNamedQuery("baz").setParameter("bar", bar).setParameter("i", i).getSingleResult();
return result;
}
}
Run Code Online (Sandbox Code Playgroud)