|
此文章由 dongsummer 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 dongsummer 所有!转贴必须注明作者、出处和本声明,并保持内容完整
May this help?
- FYI:http://timezra.blogspot.com/2008 ... oracle-stored.html:
Call The Stored Procedure From Hibernate
Now that we have a PL/SQL Stored Procedure, we will need a way to reference it from Hibernate. We can annotate the domain Object(JPA?) with such a named query.
....
@Entity
@org.hibernate.annotations.NamedNativeQuery(name = "findByLastName", query = "call findByLastName(?, :vLastName)", callable = true, resultClass = Author.class)
@Table(name = "AUTHOR", schema = "MY_ORCL")
public class Author implements java.io.Serializable {
.....
Now we can add a method to our AuthorDAO for calling this Stored Procedure.
....
@SuppressWarnings("unchecked")
public List<Author> findByLastNameUsingStoredProcedure(final String lastName) {
return (List<Author>) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(final Session session) throws HibernateException, SQLException {
return session.getNamedQuery("findByLastName") //
.setParameter("vLastName", lastName) //
.list();
}
});
}
.... |
|