Results 1 to 2 of 2

Thread: [Hibernate] updating half an entity with HibernateTemplate

  1. #1
    Join Date
    Jun 2011
    Posts
    1

    Default [Hibernate] updating half an entity with HibernateTemplate

    Hi, I´m using Spring 3.0.5 and Hibernate 3 in my project, updating my entities with HibernateTemplate:

    getHibernateTemplate().saveOrUpdate(myEntityVO);

    But for updating just some columns of my database I need to do it with HQL with:
    getHibernateTemplate().bulkUpdate(query);
    otherwise the values of myEntityVO that I don't want to update are overwritten to NULL.

    Does anybody know a way to avoid HQL for this kind of update, using for example, Criteria?

    Thank you in advanced.

  2. #2
    Join Date
    Apr 2008
    Location
    Seville, Spain
    Posts
    133

    Default

    Code:
    e = getHIbernateTemplate().getSession().get(YourEntity.class, yourEntity.getId());
    e.setOne(yourEntity.getOne());
    e.setTwo(yourEntity.getTwo());
    ....
    Jose Luis Martin
    Freelance Senior Consultant
    JDAL - Java Database Application Library

Tags for this Thread

Posting Permissions

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