i am sorry i am new to hibernate
please help me out i am trying to call a stored procedure(MS sqlserver) using
hibernate,IDE Net beans 6.9 whose return values are from two tables.
I have created mapping files and entity classes for both the table,
Created the mapping files and entity class for the Stored procedure,calling the store procedure using named query
Entity ClassCode:
package finalpkg;
public class Login_Validate {
String id;
String LM_Code;
String LM_Name;
String LM_Add1;
String LM_Add2;
String LM_Add3;
String LM_Add4;
String LM_Pin;
String LM_Phone;
String LM_Fax;
String LM_Email;
String LM_Usertype;
String Unit_Code;
String Pre_Issue_LM;
String Post_Issue_LM;
String Lm_Type;
public String getLM_Add1() {
return LM_Add1;
}
public void setLM_Add1(String LM_Add1) {
this.LM_Add1 = LM_Add1;
}
public String getLM_Add2() {
return LM_Add2;
}
public void setLM_Add2(String LM_Add2) {
this.LM_Add2 = LM_Add2;
}
public String getLM_Add3() {
return LM_Add3;
}
public void setLM_Add3(String LM_Add3) {
this.LM_Add3 = LM_Add3;
}
public String getLM_Add4() {
return LM_Add4;
}
public void setLM_Add4(String LM_Add4) {
this.LM_Add4 = LM_Add4;
}
public String getLM_Code() {
return LM_Code;
}
public void setLM_Code(String LM_Code) {
this.LM_Code = LM_Code;
}
public String getLM_Email() {
return LM_Email;
}
public void setLM_Email(String LM_Email) {
this.LM_Email = LM_Email;
}
public String getLM_Fax() {
return LM_Fax;
}
public void setLM_Fax(String LM_Fax) {
this.LM_Fax = LM_Fax;
}
public String getLM_Name() {
return LM_Name;
}
public void setLM_Name(String LM_Name) {
this.LM_Name = LM_Name;
}
public String getLM_Phone() {
return LM_Phone;
}
public void setLM_Phone(String LM_Phone) {
this.LM_Phone = LM_Phone;
}
public String getLM_Pin() {
return LM_Pin;
}
public void setLM_Pin(String LM_Pin) {
this.LM_Pin = LM_Pin;
}
public String getLM_Usertype() {
return LM_Usertype;
}
public void setLM_Usertype(String LM_Usertype) {
this.LM_Usertype = LM_Usertype;
}
public String getLm_Type() {
return Lm_Type;
}
public void setLm_Type(String Lm_Type) {
this.Lm_Type = Lm_Type;
}
public String getPost_Issue_LM() {
return Post_Issue_LM;
}
public void setPost_Issue_LM(String Post_Issue_LM) {
this.Post_Issue_LM = Post_Issue_LM;
}
public String getPre_Issue_LM() {
return Pre_Issue_LM;
}
public void setPre_Issue_LM(String Pre_Issue_LM) {
this.Pre_Issue_LM = Pre_Issue_LM;
}
public String getUnit_Code() {
return Unit_Code;
}
public void setUnit_Code(String Unit_Code) {
this.Unit_Code = Unit_Code;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
Mapping File--Login_Validate.hbm.xml Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="finalpkg.Login_Validate">
<property name="id"/>
<property name="LM_Code"/>
<property name="LM_Name"/>
<property name="LM_Add1"/>
<property name="LM_Add2"/>
<property name="LM_Add3"/>
<property name="LM_Add4"/>
<property name="LM_Pin"/>
<property name="LM_Phone"/>
<property name="LM_Fax"/>
<property name="LM_Email"/>
<property name="LM_Usertype"/>
<property name="Unit_Code"/>
<property name="Pre_Issue_LM"/>
<property name="Post_Issue_LM"/>
<property name="Lm_Type"/>
</class>
<sql-query name="login" callable="true">
<return alias="login" class="finalpkg.Login_Validate">
<return-property name="id" column="id"/>
<return-property name="LM_Code" column="LM_Code"/>
<return-property name="LM_Name" column="LM_Name"/>
<return-property name="LM_Add1" column="LM_Add1"/>
<return-property name="LM_Add2" column="LM_Add2"/>
<return-property name="LM_Add3" column="LM_Add3"/>
<return-property name="LM_Add4" column="LM_Add4"/>
<return-property name="LM_Pin" column="LM_Pin"/>
<return-property name="LM_Phone" column="LM_Phone"/>
<return-property name="LM_Fax" column="LM_Fax"/>
<return-property name="LM_Email" column="LM_Email"/>
<return-property name="LM_Usertype" column="LM_Usertype"/>
<return-property name="Unit_Code" column="Unit_Code"/>
<return-property name="Pre_Issue_LM" column="Pre_Issue_LM"/>
<return-property name="Post_Issue_LM" column="Post_Issue_LM"/>
<return-property name="Lm_Type" column="Lm_Type"/>
</return>
exec BRLM_Login_Validate :username,:pass
</sql-query>
</hibernate-mapping>
Hibernate Config fileCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://..;databaseName=general</property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
<mapping resource="Lead_Manager_Info.hbm.xml"/>
<mapping resource="Lead_Manager_Master.hbm.xml"/>
<mapping resource="Login_Validate.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Main ClassCode:
public class Main {
static SessionFactory sf=null;
static
{
sf=HibernateUtil.getSessionFactory();
}
public static void main(String[] args) {
// TODO code application logic here
/* Session s=sf.openSession();
Lead_Manager_Info l=(Lead_Manager_Info)s.get(Lead_Manager_Info.class,2);
System.out.println("Unit code"+l.getUnit_code());
s.close();
Session ss=sf.openSession();
Lead_Manager_Master lm=(Lead_Manager_Master)ss.get(Lead_Manager_Master.class,10);
System.out.println("LM"+lm.getLm_Id());
ss.close();*/
Session sss=sf.openSession();
Transaction t=sss.beginTransaction();
Query q=sss.getNamedQuery("login");
q.setParameter("username","username");
q.setParameter("pass","***" );
List<Login_Validate> ll=(List<Login_Validate>)q.list();
for(int i=0;i<ll.size();i++)
{
Login_Validate lv=ll.get(i);
System.out.println("Proc === == "+lv.getLM_Name());
}
t.commit();
sss.close();
}