-->
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.  [ 6 posts ] 
Author Message
 Post subject: hibernate session.load throwing no row with id found
PostPosted: Wed Aug 18, 2010 8:53 am 
Newbie

Joined: Wed Aug 18, 2010 8:46 am
Posts: 2
code snippet:
Address addr = (Address)session.load(Address.class, new Long(1));

addr.setCity("Bangalore");
addr.setState("Karnataka");
addr.setStreet("bowee");
addr.setZipcode("560008");
session.update(addr);
transaction.commit();
============================================
there is one address record with id 1

hbm file for address pojo class is

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="javabeat.net.hibernate.Address" table="ADDRESS">
<meta attribute="class-description">This class contains the student's address
details.</meta>
<id name="addressId" type="long" column="ADDRESS_ID">
<generator class="increment" />
</id>
<property name="street" column="ADDRESS_STREET" type="string" length="250" />
<property name="city" column="ADDRESS_CITY" type="string" length="50" />
<property name="state" column="ADDRESS_STATE" type="string" length="50" />
<property name="zipcode" column="ADDRESS_ZIPCODE" type="string" length="10" />
</class>
</hibernate-mapping>

please help why am i getting this error.


Top
 Profile  
 
 Post subject: Re: hibernate session.load throwing no row with id found
PostPosted: Wed Aug 18, 2010 1:39 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2008 8:18 am
Posts: 35
please send the code, what type of error are you getting.


Top
 Profile  
 
 Post subject: Re: hibernate session.load throwing no row with id found
PostPosted: Wed Aug 18, 2010 4:23 pm 
Newbie

Joined: Tue Aug 17, 2010 3:29 pm
Posts: 12
see whether the record in the database is commited. This could be one of the possible reasons.


Top
 Profile  
 
 Post subject: Re: hibernate session.load throwing no row with id found
PostPosted: Thu Aug 19, 2010 4:08 am 
Newbie

Joined: Wed Aug 18, 2010 8:46 am
Posts: 2
code:
address.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="javabeat.net.hibernate.Address" table="ADDRESS">
<meta attribute="class-description">This class contains the student's address
details.</meta>
<id name="addressId" type="long" column="ADDRESS_ID">
<generator class="increment" />
</id>
<property name="street" column="ADDRESS_STREET" type="string" length="250" />
<property name="city" column="ADDRESS_CITY" type="string" length="50" />
<property name="state" column="ADDRESS_STATE" type="string" length="50" />
<property name="zipcode" column="ADDRESS_ZIPCODE" type="string" length="10" />
</class>
</hibernate-mapping>

=======================================================================================

hibernate.configuration file:
<?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">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/hkbk</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create-drop</property>

<!-- mapping resource-->
<mapping resource="javabeat/net/hibernate/Student.hbm.xml"/>
<mapping resource="javabeat/net/hibernate/Address.hbm.xml"/>
<mapping resource="javabeat/net/hibernate/Course.hbm.xml"/>
</session-factory>
</hibernate-configuration>
==========================================================================================

code to enter records in data base:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package javabeat.net.hibernate;

/**
*
* @author juahmed
*/
import java.util.HashSet;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;



public class JavaBeatHibernateExample {

public static void main(String[] args) {
Session session = null;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
Address address = new Address("OMR Road", "Bangalore", "KARNATAKA", "560008");
//By using cascade=all option the address need not be saved explicitly when the student object is persisted the address will be automatically saved.
//session.save(address);
Set<Course> courses = new HashSet<Course>();
courses.add(new Course("Maths"));
courses.add(new Course("Computer Science"));
Student student1 = new Student("Eswar", address, courses);
Student student2 = new Student("Joe", address, courses);
session.save(student1);
session.save(student2);

transaction.commit();
} catch (Exception e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}

}

}
========================================================
code to update the database record:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package javabeat.net.hibernate;

/**
*
* @author juahmed
*/
import java.util.HashSet;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;



public class JavaBeatHibernateExampleUpdate {

public static void main(String[] args) {
Session session = null;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
Address addr = (Address)session.load(Address.class, new Long(1));

addr.setCity("Bangalore");
addr.setState("Karnataka");
addr.setStreet("bowee");
addr.setZipcode("560008");
session.update(addr);
transaction.commit();
} catch (Exception e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}

}

}
==================
address record is present in database with id=1.


please help me.


Top
 Profile  
 
 Post subject: Re: hibernate session.load throwing no row with id found
PostPosted: Thu Aug 19, 2010 10:23 am 
Newbie

Joined: Tue Aug 17, 2010 3:29 pm
Posts: 12
I think to update you dont need to load it first. create a pojo, assign the id directly to it, assign all other values and call update on it. it should work.


Top
 Profile  
 
 Post subject: Re: hibernate session.load throwing no row with id found
PostPosted: Thu Aug 19, 2010 11:43 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 8:18 am
Posts: 35
This code is looking fine. I ran it by taking your code, it's running fine in Oracle.
Check your database whether it's support "increment" generate key or not.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.