-->
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.  [ 8 posts ] 
Author Message
 Post subject: update not reflected in the database
PostPosted: Mon Mar 08, 2004 2:29 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
When an update is issued to the database I don't see the update in the database. Hibernate prints the SQL statement. When i run that in the SQL editor the statement excutes fine with no errors. Can anyone let me know what are the points to be noted.

1. I load the data
2. set the new date
3. saveorupdate the data

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 2:30 pm 
Beginner
Beginner

Joined: Thu Feb 05, 2004 10:39 pm
Posts: 44
Do you do a session.flush() or Transaction.commit() after your saveOrUpdate?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 2:31 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
Yes. I do.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 2:33 pm 
Beginner
Beginner

Joined: Thu Feb 05, 2004 10:39 pm
Posts: 44
well, you will at least probebly have to post the code here.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 2:51 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
<?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.trulogica.truaccess.request.model.EmailVerificationData"
table="EmailVerification"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="emailVerificationId"
column="emailVerificationId"
type="int"
unsaved-value="0"
>
<generator class="com.trulogica.truaccess.idgen.util.HibernateIdGenerator">
<param name="TableName">EmailVerification</param>
</generator>
</id>

<property
name="creationTime"
type="date"
update="true"
insert="true"
column="creationTime"
/>

<property
name="EMail"
type="string"
update="true"
insert="true"
column="eMail"
/>

<property
name="GUID"
type="string"
update="true"
insert="true"
column="GUID"
/>

<property
name="instActivityId"
type="int"
update="true"
insert="true"
column="activityId"
/>

<property
name="keyField"
type="string"
update="true"
insert="true"
column="keyField"
/>

<property
name="status"
type="string"
update="true"
insert="true"
column="status"
/>

<property
name="verificationTime"
type="date"
update="true"
insert="true"
column="verificationTime"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-EmailVerificationData.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>







public void updateEmailVerificationData (EmailVerificationData emailVerificationData)
throws EmailVerificationException
{
Session session = null;
mLogger.finer("Entering the emailVerification table with " + emailVerificationData.toString());
try
{
session = PersistenceManager.getSession();
EmailVerificationData data =
(EmailVerificationData) session.load(
EmailVerificationData.class,
new Integer(emailVerificationData.getEmailVerificationId()));
mLogger.finer("Data loaded from the database is " +data.toString());
data.setStatus(emailVerificationData.getStatus());
data.setVerificationTime(emailVerificationData.getVerificationTime());
session.saveOrUpdate(data);
session.flush();
}
catch (Exception e)
{
mLogger.log(
Level.WARNING,
"[Exception] when updating the email verification data with verification data " + emailVerificationData.toString(),
e);
throw new EmailVerificationException(e);
}
finally
{
try
{
PersistenceManager.closeSession(session);
}
catch (HibernateException e)
{
throw new EmailVerificationException(e);
}
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 3:37 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
If i do a insert and then read it and print it, the record is printable. But its not in the data base ? Any clues ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 6:56 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Use a transaction

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 8:39 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Ya, you say you do use a transaction but where are you calling "session.beginTransaction()" in your code? You're not. So you're not really using a transaction.

Try this:

Code:
session = PersistenceManager.getSession();
Transaction tx = session.beginTransaction(); // NEW
EmailVerificationData data =
(EmailVerificationData) session.load(
EmailVerificationData.class,
new Integer(emailVerificationData.getEmailVerificationId()));
mLogger.finer("Data loaded from the database is " +data.toString());
data.setStatus(emailVerificationData.getStatus());
data.setVerificationTime(emailVerificationData.getVerificationTime());
session.saveOrUpdate(data);
session.flush();
tx.commit(); // NEW


Cheers,
Rob


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.