I'm a beginner in hibernate and till this date I have not come across stored procedures.
Can somebody tell me how to execute the following in Hibernate, this stored procedure returns three fields
date, balance, name_of_person
execute procedures 'dfd' 'fdf' '34'
Whether I need to Create the bean in such a way that the bean has the following fields: date, balance, name_of_person
Whether I need to create the property file?
Is it possible to use Criteria for executing procedures in hibernate?
If I the NativeQuery is the only option, then how can I create the property file as I don't have the such a table as the result from the procedure
Is it possible to use native query alone without, using any bean or property file, and printing the results
Here's 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>
Code
List<MyBean> list = sessionFactory.getCurrentSession()
.getNamedQuery("mySp")
.setParameter("name", name)
.setResultTransformer(Transformers.aliasToBean(MyBean.class))
.list();
Bean class
This bean holds the results from the stored procedure. The field names must match the column names from the Hibernate mapping file.
public class MyBean {
private Date date;
private Long balance;
private String name_of_person;
// getters and setters
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With