-->
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.  [ 11 posts ] 
Author Message
 Post subject: Update Specific Column
PostPosted: Sat May 28, 2005 2:25 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.3

Name and version of the database you are using:
PostgreSQL

Hi

How can i update specific Column in an Table.

Consider I have 5 columns in a table and i need to update only 2 columns

If I use session.update(), it updates the other 3 columns to 0 if its an int type in the Database.

How do i do it?

I am not able to use session.merge() it doesnt work properly, It also doesnt work properly in Hibernate 3.0.5

Waiting for a Solution

Regards
RamnathN


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 28, 2005 3:01 pm 
Regular
Regular

Joined: Tue May 24, 2005 10:19 am
Posts: 65
In class element , try yse dynamic-update, dynamic-insert eement
Quote:
( Specifies that UPDATE SQL/INSERT SQL should be generated at runtime and contain only those columns whose values have changed.)

and in property element, try use update, insert
Quote:
(update, insert (optional - defaults to true) : specifies that the mapped columns should be included in SQL UPDATE and/or INSERT statements. Setting both to false allows a pure "derived" property whose value is initialized from some other property that maps to the same colum(s) or by a trigger or other application.)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 3:48 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

I have set dynamic-update="true",but it issues a select statement before.

The result is the same.

session.update() updates all the column.

Can anybody help me?

Regards
RamnathN

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 8:57 am 
Regular
Regular

Joined: Tue May 24, 2005 10:19 am
Posts: 65
try....in property element, try use update, insert
(
Quote:
update, insert (optional - defaults to true) : specifies that the mapped columns should be included in SQL UPDATE and/or INSERT statements. Setting both to false allows a pure "derived" property whose value is initialized from some other property that maps to the same colum(s) or by a trigger or other application.
)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 9:06 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

I cannot give update="false" in the property because i can update all the columns in one condition and i want to update a single column in one condition.

So i cannot put the update as false.

Do u have anyother solution for this?

Waiting for a reply

Regards
RamnathN


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 9:17 am 
Regular
Regular

Joined: Tue May 24, 2005 10:19 am
Posts: 65
you can try....
1) manipulate metadata in runtime for disable/enable update of this property
2) try break your class in 2.
3) make impossible change the value of this property

for more help, put more info!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 12:24 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

This the mapping file.

<hibernate-mapping>
<class name="newauctioninfo.Bid" table="Bid">
<id name="bid_id" type="int" column="bid_id">
<generator class="assigned"></generator> </id>
<property name="bid_amount" type="int" column="bid_amount"></property>
<many-to-one name="item" class="newauctioninfo.Item" column="item_id"></many-to-one>
</class>

<class name="newauctioninfo.Item" table="Item" dynamic-update="true" >
<id name="item_id" type="int" column="item_id">
<generator class="increment"></generator></id>
<property name="item_name" type="string" column="item_name"></property>
<property name="item_desc" type="string" column="item_desc"></property>
<property name="item_price" type="int" column="item_price"></property>
<bag name="bids" lazy="true" inverse="true" cascade="all">
<key column="item_id"/>
<one-to-many class="newauctioninfo.Bid"/>
</bag>
</class>
</hibernate-mapping>


And this is my code

Item item = new Item();
item.setItem_id(8);
item.setItem_name("ramn");
// item.setItem_price();
// item.setItem_desc();
session.update(item);


I want to insert only the item Name .

Waiting for ur reply

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 4:07 pm 
Regular
Regular

Joined: Tue May 24, 2005 10:19 am
Posts: 65
1)you can try break your class in 2.
class withname class
{}
class withproperties class extends withname
{}

2)you can use 2 sessions configurations, one with all properties, other not.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 5:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Or you could just use the HQL UPDATE statement

http://www.hibernate.org/hib_docs/v3/reference/en/html/batch.html#batch-direct


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 12:56 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Thanks Steve

I got the HQL update working. I can update specific Column


Thanks zesj

For helping me solve the problem

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 7:30 am 
Newbie

Joined: Thu Jun 02, 2005 7:24 am
Posts: 1
zesj wrote:
you can use 2 sessions configurations, one with all properties, other not.

I have tried the second approach, but it is not very elegant beacuse I have to subclass of my original POJO and link the subcalss to the second session configuration. I.e class A whith all update/insert=true and classB extends class A with update/insert=true only on the columns to be updated.
Is there any other way to tell hibernate to use the second session configuration?


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