Results 1 to 3 of 3

Thread: Insert Update and Delete in single query using HibernateTemplate

  1. #1
    Join Date
    Jul 2011
    Posts
    11

    Default Insert Update and Delete in single query using HibernateTemplate

    I want to Insert/Update/Delete from DB in a single query using Hibernate template then which query do i need to use?

    I tried using saveupdate/saveUpdateAll it is updating and inserting the records but not deleting.

    For e.g.

    Employee object has a list of Address objects.
    Initially i have 2 address object set in Employee object and i remove one object and call saveupdate or saveupdateall or merge method of hibernate template still it is not deleting one record from DB.

    Need help!
    Thanks.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Then you have something wrong in your mapping... The fact that you delete it from a collection doesn't mean it is deleted from the database (the relation between the 2 is deleted!). If you want to delete the address you need to specify delete-orphan (which is only supported by hibernate and not JPA!).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jul 2011
    Posts
    11

    Default

    Hi Marten,
    Thanks for your reply.
    I used orphan-removal=true in my annotations and it worked with hibernate template's merge method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •