Announcement Announcement Module
Collapse
No announcement yet.
A few questions related to data access Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A few questions related to data access

    Hi all, I am a new to Spring-hibernate and have a few basic questions. So here goes :

    1) I have a table and a business object. However, after processing, I need to do a batch update and set the flag of 1 field. Is there a way to do a batch update with a single SQL such as :Update tbl set flag="P" where time=xx" instead of looping thru all my TBL object, set the flag property and call saveOrUpdate for each object ?

    2) I am having a problem with saveOrUpdate call for all my objects. When I try a saveOrUpdate when it should actually be an INSERT, it is still trying to do an UPDATE and failing. I am not sure how to set the unsaved-value flag for composite keys so that hibernate can identify taht record as a new one. Also, what is versioning/timestamp? Do I have to do that for the saveOrUpdate to work ?

    Thanks again for helping me out.

  • #2
    Hibernate can help you with both issues. I advice you to read Hibernate reference documentation and if you can, buy the Hibernate in Action book - it explains in detail what Hibernate does and how.
    To briefly answer your questions:

    1. HB (especially 3.1.x) supports bulk operations and you should definitely use these features for fast processing. The answer would be: no, you don't have to do that if you are using BULK updates.

    2. Check the Hibernate documentation - unsaved-value provides a good hint for hibernate about the state of your objects and you should use it. Also versioning is a good thing to have since it offers you support against stale data - you don't have to use it to make saveOrUpdate work - focus on unsaved-value instead.

    Comment

    Working...
    X