-->
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: Data is not written to database
PostPosted: Sat Dec 25, 2004 11:31 pm 
Newbie

Joined: Sat Dec 25, 2004 11:18 pm
Posts: 11
Hibernate version: 2.1.7

Hello Guys

I am a hibernate newbie and having some start up problem. I must be doing something silly but i need someone to point me out in right direction.
I am running a example given on site :
http://homepage.mac.com/edahand/project ... mple1.html
to jump start on tomcat, struts, hibernate and mysql. Example works fine
but data is not getting into database. When i go to database, table is blank.....
Code and details are:

mapping file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.ehand.hibernatetest.Item" table="item" >
<id name="id" column="id" type="java.lang.Long" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="description" column="description" type="java.lang.String" />
</class>
</hibernate-mapping>

code for adding to database:

Session session = getSession();

try
{
session.save(item);
session.flush();

}
catch (HibernateException e)

Could some one point me why it is not getting into database.....


Thanks in advance for help

Manan


Top
 Profile  
 
 Post subject: Re: Data is not written to database
PostPosted: Sun Dec 26, 2004 4:53 am 
Newbie

Joined: Fri Dec 24, 2004 11:24 am
Posts: 5
write out the full stack trace of the exception

mananmehra wrote:
Hibernate version: 2.1.7

Hello Guys

I am a hibernate newbie and having some start up problem. I must be doing something silly but i need someone to point me out in right direction.
I am running a example given on site :
http://homepage.mac.com/edahand/project ... mple1.html
to jump start on tomcat, struts, hibernate and mysql. Example works fine
but data is not getting into database. When i go to database, table is blank.....
Code and details are:

mapping file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.ehand.hibernatetest.Item" table="item" >
<id name="id" column="id" type="java.lang.Long" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="description" column="description" type="java.lang.String" />
</class>
</hibernate-mapping>

code for adding to database:

Session session = getSession();

try
{
session.save(item);
session.flush();

}
catch (HibernateException e)

Could some one point me why it is not getting into database.....


Thanks in advance for help

Manan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 26, 2004 8:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Start using the transaction API


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 26, 2004 10:49 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
michael wrote:
Start using the transaction API


In other words, your data may still be in a transaction even though you have flushed the session.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 26, 2004 7:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
This section of code is incomplete

Quote:
Session session = getSession();

try
{
session.save(item);
session.flush();

}
catch (HibernateException e)


A typical transaction should use the following idiom:
Code:
Session sess = factory.openSession();
Transaction tx;
try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
}
catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
}
finally {
     sess.close();
}


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Tue Dec 28, 2004 12:18 pm 
Newbie

Joined: Sat Dec 25, 2004 11:18 pm
Posts: 11
Thanks A lot. As soon as i added commit to the code, it started working...


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.