-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Problem in getting data from database
PostPosted: Tue Aug 02, 2005 1:53 am 
Newbie

Joined: Tue Aug 02, 2005 1:33 am
Posts: 2
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:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 2:50 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Turn show_sql on (in your hibernate.properties) and post you SQL output as well as your log file.

If that doesn't give a clue, switch your logging level to debug (log4j.logger.org.hibernate=DEBUG) and post this log file as well.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 2:53 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
By the way your getter/setter for pkId should be:

Code:
public int getPkId() {
   return pkId;
}

public void setPkId(int pkId) {
   this.pkId = pkId;
}


You don't get an exception with this?

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 5:23 am 
Newbie

Joined: Tue Aug 02, 2005 1:33 am
Posts: 2
sven wrote:
By the way your getter/setter for pkId should be:

Code:
public int getPkId() {
   return pkId;
}

public void setPkId(int pkId) {
   this.pkId = pkId;
}


You don't get an exception with this?

Best regards
Sven


Thanks Sven for your input but i am sorry i pasted some wrong code the code as is shown i am resending the code sorry for the mistake.

package vitalwebadmin.pojo;

public class Role {

public Role()
{
}

String roleName;
int categoryId;
int roleId;

public int getPkId()
{
return roleId;
}

public int getRoleId()
{
return roleId;
}

public String getRoleName()
{
return roleName;
}

public void setPkId(int RoleId)
{
this.roleId = RoleId;
}

public void setRoleId(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;
}

}


<?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="roleId" type="int">
<column name="roleId" sql-type="int"/>
</id>


<property name="roleName"/>
<property name="categoryId"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 4:51 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
See my first posting in this thread again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 7:40 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
I remember having to change the hbm2ddl.auto property to update to prevent the table data from being dropped.

Do you have hbm2ddl.auto property in hibernate.properties or hibernate.cfg.xml set to 'create' by chance? if so, change it to...

hibernate.hbm2ddl.auto=update


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 8:20 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Can you post your hibernate.cfg.xml file ?

If you don't have a <mapping> element for your Role object or add it manually to the Configuration, which I can see you are not, this can be the result. It doesn't throw an exception, it just doesn't return any results.

Your hibernate.cfg.xml file should have a line like this one.

<mapping resource="vitalwebadmin/pojo/Role.hbm.xml"/>

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.