-->
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.  [ 1 post ] 
Author Message
 Post subject: Junk updated in table
PostPosted: Thu Aug 24, 2006 6:39 am 
Newbie

Joined: Mon Aug 14, 2006 6:54 am
Posts: 1
We are using Hibemnate in our project.
In a perticulat table we have Blob field. When ever we are trying to insert a new row in the table we are getting two extra update statement in theat table with the same data.
The mapping file:

<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Wed Dec 28 16:15:02 GMT+05:30 2005 -->
<hibernate-mapping package="com.unisys.ecs.server.hibernate">

<class name="ExternalDocuments" table="EXTERNAL_DOCUMENTS" >
<id name="externaldocumentcode" column="EXTERNALDOCUMENTCODE" type="java.lang.String">

<generator class="assigned"/>

</id>

<property name="externaldocumentdescription" column="EXTERNALDOCUMENTDESCRIPTION" type="java.lang.String" not-null="true" />
<property name="externaldocumentblob" column="EXTERNALDOCUMENTBLOB" type="java.sql.Blob" lazy="true" not-null="true" />
<property name="externaldocumentfilename" column="EXTERNALDOCUMENTFILENAME" type="java.lang.String" />
<!--
<property name="externaldocumenttype" column="EXTERNALDOCUMENTTYPE" type="java.lang.String" not-null="true" />
-->
<property name="lastupdated" column="LASTUPDATED" type="java.util.Date" not-null="true" />

<set name="procedureDocumentsSet" inverse="true">
<key column="EXTERNALDOCUMENTCODE"/>
<one-to-many class="ProcedureDocuments"/>
</set>
</class>

</hibernate-mapping>


The code for saving or update the object:
public Date setDocument (ExternalDocuments document,boolean isInsert) throws Exception {

Session session = null;
//Transaction tx = null;
Date lastUpdated = ECSUtilities.getDatabaseTimeStamp();
try {
session = HibernateSessionFactory.currentSession();
//tx = session.beginTransaction();
if(isInsert){
document.setLastupdated(lastUpdated);
session.save(document);
//session.isConnected();
session.flush();
//tx.commit();

System.out.println("ExternalDocuments saved successfully.......");

}else{

ExternalDocuments docFromDb = (ExternalDocuments)session.get(ExternalDocuments.class, document.getExternaldocumentcode());
if(docFromDb == null) {
throw new EntityNotFoundException();
}
else {
if(docFromDb.getLastupdated().after(document.getLastupdated()))
{
throw new StaleDataException();
}
else
{
if(document.getFile() == null)
{
document.setExternaldocumentblob(docFromDb.getExternaldocumentblob());
}
document.setLastupdated(lastUpdated);
session.evict(docFromDb);
session.flush();
session.update(document);
session.flush();
}
}


System.out.println("ExternalDocuments updated successfully.......");
}
return lastUpdated;

} catch (Exception ex) {
ex.printStackTrace();

throw ex;

}

}

Help me out.....


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

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.