Hibernation and stored procedure

I am new to hibernation and until this date I have not encountered stored procedures.

Can someone tell me how to do the following in Hibernate, this stored procedure returns three fields

date, balance, name_of_person 

execute the procedures 'dfd' 'fdf' '34'

  • Is it necessary to create a bean so that the bean has the following fields: date, balance, name_of_person

  • Do I need to create a properties file?

  • Can I use criteria to perform sleep procedures?

  • If I am the only NativeQuery variant, then how can I create a property file since I don’t have such a table as the result from the procedure

  • Is it possible to use my own query myself without using any bean file or property and print the results

+6
java stored-procedures hibernate
source share
1 answer

Here is a simple example: -

Hibernate mapping file

 <hibernate-mapping> <sql-query name="mySp"> <return-scalar column="date" type="date" /> <return-scalar column="balance" type="long" /> <return-scalar column="name_of_person" type="string" /> { call get_balance_sp :name } </sql-query> </hibernate-mapping> 

the code

 List<MyBean> list = sessionFactory.getCurrentSession() .getNamedQuery("mySp") .setParameter("name", name) .setResultTransformer(Transformers.aliasToBean(MyBean.class)) .list(); 

Bean class

This bean contains the results of the stored procedure. Field names must match the column names in the Hibernate mapping file.

 public class MyBean { private Date date; private Long balance; private String name_of_person; // getters and setters } 
+7
source share

All Articles