Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Update single column using hibernate criteria

 
kashwini Kulkarni
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,


I need to update a single column in my table using criteria.(Where all other columns are already filled with values)
If i try to update single column ,it gives me nullpointer exception for all other columns specified as not null.
Can anyone tell me what can be the correct way to do this?




Thanks in Advance
Kashwini
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First can you show us your code so that we maybe we can give you some pointers.
 
kashwini Kulkarni
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Sorry for such a late reply.....

I have a table named Product (Also POJO and hbm file for the same)

Columns of Product table:
productId Autogenerate
productName
productDetail
productQuantity

where I need to update productDetail while keeping all other columns as it is.

so I write,

Product p=new Product();
p.setProductDetail("new detail");
session.update(p);

I tried doing dynamic-update="true" but no luck.

Is there any way to update single column of a table using session.update(); ?


Thanks in advance
Kashwini
 
Jitesh Sinha
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to specify other two columns - name and quantity.
If these columns are specified as not null as you said you cannot expect to save a row in the table without specifying them.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to update something yet you're creating a new object. You probably want:

 
kashwini Kulkarni
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,


Thanks a lot for you replies.

The problem got solved by using

Product product = (Product) session.get(Product.class, productId);
product.setProductDetail("new detail");


I searched the net for entire two days but was unable to find this.
Thanks a lot once again Wouter Oet.




Regards,
Kashiwni
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic