Hi,
i am lakshmi and am new to hibernate concepts. i am working on Hibernate version 3.0.
i am unable retreive data properly from the database.
while i try to retreive data all the rows in my table get deleted from the database.
also for any transaction made the code is deleting the relationships built accross tables in the database.but there are no exceptions thrown
This is my mapping file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"file://D:/hibernate 3.0.5/hibernate-3.0/src/org/hibernate/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="vitalwebadmin.pojo.Role" table="Role">
<id name="pkId" type="int" unsaved-value="null" >
<column name="pkId" sql-type="int" not-null="true"/>
</id>
<property name="roleName"/>
<property name="categoryId"/>
</class>
</hibernate-mapping>
This is my pojo
package vitalwebadmin.pojo;
public class Role {
public Role()
{
}
String roleName;
int categoryId;
int pkId;
public int getpkId()
{
return roleId;
}
public String getRoleName()
{
return roleName;
}
public void setpkId(int RoleId)
{
this.roleId = RoleId;
}
public void setRoleName(String RoleName)
{
this.roleName = RoleName;
}
public int getCategoryId()
{
return categoryId;
}
public void setCategoryId(int CategoryId)
{
this.categoryId = CategoryId;
}
}
The database we are using is SQLSERVER2000.the server side code to retreive is as follows
java code to retreive data
public String getRole()
{
Role roleData = new Role();
String str="";
System.out.println("GETTING DATA");
SessionFactory factory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
System.out.println("CREATED FACTORY");
Session session = factory.openSession();
System.out.println("OPNED SESSION");
Transaction tx = session.beginTransaction();
System.out.println("TRANSACTION BEGAN....");
Query query = session.createQuery("select role from package.Role as role where role.pkId=1");
// query.setParameter("RoleName", "Physician", Hibernate.STRING);
// System.out.println("CREATE QUERY.............." + query.getClass() );
//uery.setParameter("RoleId", 1, Hibernate.INTEGER);
// query.setString("RoleName", "Physician");
for (java.util.Iterator it = query.iterate(); it.hasNext();)
{
roleData = (Role) it.next();
System.out.println("VALUES ARE :"+roleData.getRoleId());
str = str + showData(roleData);
}
System.out.println("7");
tx.commit();
return str;
}
Your response is of immense value to me.please do help me in solving this problem
regards,
Lakshmi.
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: