-->
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.  [ 4 posts ] 
Author Message
 Post subject: newbie question: update only certain column
PostPosted: Wed Jan 05, 2005 5:19 pm 
Newbie

Joined: Wed Jan 05, 2005 4:59 pm
Posts: 15
Hibernate version:2.1.7c, 24.11.2004

Mapping documents:
<hibernate-mapping>
<class name="mypackage.X12Transaction"
table="TRANSACTION"
dynamic-update="true"
dynamic-insert="true">
<id name="id" type="long" column="TRXID" unsaved-value="null">
<generator class="sequence">
<param name="sequence">CSRSEQUENCE</param>
</generator>
</id>
<property name="userId" column="TRANSUSERID" type="integer"/>
<property name="transactionPerformed" column="TRANSPERFORMED" type="string"/>
<property name="transactionStatus" column="TRANSSTATUS" type="string"/>
<property name="transactionDate" column="TRANSDATE" type="java.util.Date"/>
<property name="transactionIdentifier" column="TRANSIDENTIFIER" type="string"/>
<property name="x12In" column="X12IN" type="java.sql.Clob"/>
<property name="x12Out" column="X12OUT" type="java.sql.Clob"/>
</class>
</hibernate-mapping>


Name and version of the database you are using: oracle 10g

In the table TRANSACTION, when we first insert a record into the table X12IN column gets populated along with others. X12OUT is not populated in the insert. So far so good, this part worked fine.

some processing happens then I get the x12out data.

Now I am trying to update the record by updating the X12OUT column. The update call wipes out the X12IN column. When I am passing the X12Transaction instance to the update, I think the X12IN is not present.

My question is how can I update only the X12OUT field. Here I know the TRXID, so like in plain JDBC I can accomplish this with the sql query like:

UPDATE TRANSACTION
SET X12OUT = ?
WHERE TRXID =?


How can I achieve the same in hibernate? I bought the e-book hibernate in action, which chapter specifically addresses this?

Any help will be much appreciated.

TIA

Rumpa Giri


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 5:39 pm 
Newbie

Joined: Wed Jan 05, 2005 4:59 pm
Posts: 15
Found one way to do it, I am sure there is another way.

When I load the record by id by doing the following and then calling update, the generated sql is what I am looking for.

x12 = (X12Transaction) session.load(X12Transaction.class, new Long(_id));

Then update call results in:

Hibernate: update TRANSACTION set X12OUT=? where TRXID=?

The load by id, does that makes a select call?

In that case is there a way to do the column update only without the overhead of the select sql?

TIA
Rumpa Giri


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 9:43 pm 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
girirx wrote:
Found one way to do it, I am sure there is another way.

When I load the record by id by doing the following and then calling update, the generated sql is what I am looking for.

x12 = (X12Transaction) session.load(X12Transaction.class, new Long(_id));

Then update call results in:

Hibernate: update TRANSACTION set X12OUT=? where TRXID=?

The load by id, does that makes a select call?


It might if the an object with that identity has not already been loaded, or is not in the cache.

girirx wrote:
In that case is there a way to do the column update only without the overhead of the select sql?


When Hibernate loads an object, it must load all of it's properties. Otherwise, the object would be left in a strange state.

The new UPDATE command (planned for Hibernate3) will be able to update a single property of an object, but of course this kind of change will not be reflected in the objects in the current session for the very same reason.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 3:52 pm 
Newbie

Joined: Wed Jan 05, 2005 4:59 pm
Posts: 15
Thank you for your reply.

I will read more about cache then.

Thanks again,
Rumpa Giri


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