• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

how to use selective update with dynamicUpdate ?

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm trying to update by primary-key-selective. In other words, say I have an obj of class Employee




and I wish to change only the age, how can I create a temp obj Employee and set the primeryKey and the new age and simply update selectivly only the fields that are not null?

I read that I need to use

but it didn't work for me.

code sample:


THANK YOU!
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well first you'd have to know if the employee's there on the db right? so are you sure that this id is correct? ... I'd do a find by example (constructed as you state above) and basically then update the age and run an update ....

Trilochan
 
Adrian Burlington
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it's not in the db - I expect that an exception will be thrown.
To do Select before every update sounds like a very inefficient procedure.

Is there a way to do it with updateByPrimeryKeySelctive?
 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saveOrUpdate( ) works the same way, will basically do an insert if the employees not there, otherwise do an update.

Trilochan.
 
Adrian Burlington
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trilochan - your answer has nothing to do with the question I presented.
saveOrUpdate will not do the update selectively.

I'm looking for a selective update (not insert)

thanks

 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be I am missing your whole point horribly ... long work hours maybe? ;)

Well then lets take another stab at your problem, first things first, give me your stack trace ( You said it didn't work for me ) what was wrong with it? Bear in mind though that this is what happens when you do update( ) (logically ... read the code if your curious).

Step 1 : calls fireSaveOrUpdate( ) event with new SaveOrUpdateEvent
Step 2 : during this, corresponding listener is invoked (DefaultSaveOrUpdateListener) and onSaveOrUpdate( ) is called.
Step 3 : A check is made to see if entity is detached or transient or persistent
Step 4 : If persistent or detached which is what your case it should be, it performs an update.


Your example should work! paste:
1.) calling code
2.)hbm files
3.) stack trace
4.) any other setup that you used.


Trilochan.
 
Hot dog! An advertiser loves us THIS much:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!