-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Rows updated (or deleted) on select if setter is empty
PostPosted: Sun Jun 26, 2011 6:40 am 
Newbie

Joined: Sat Jun 25, 2011 6:53 pm
Posts: 2
Hello,

If there is an empty setter method in a mapped class then on issuing a select (fetch all) hibernate executes an update - on the column, or delete on a table depending on the mapping.

a) Can anyone tell me why exactly this is happening?
(I am not new to hibernate but I am not well versed with it either.)
b) Can hibernate be configured ('fixed') not to do this?
c) Should this be reported as a bug?

Below is the 'Person' class and its mapping.
The 'Address' class and its mapping is not included but for those who would like to reproduce it, the generator mapping for the 'Address' was 'assigned'.

Code:

package hib.example.model.pojo.bean;

import java.util.Set;

public class Person {
   
   private long slNo;
   private String name;
   private int age;
   private Address address;
   private Set<Address> addresses;
   
   
   public long getSlNo() {
      return slNo;
   }
   public void setSlNo(long slNo) {
      this.slNo = slNo;
   }
   public String getName() {
      return name;
   }
   public void setName(String name) {
      /*
       * comment below code for recreating - update on select - behaviour 
       */
      this.name = name;
   }
   
   public int getAge() {
      return age;
   }
   public void setAge(int age) {
      this.age = age;
   }
   public Address getAddress() {
      return address;
   }
   public void setAddress(Address address) {
      this.address = address;
   }
   public Set<Address> getAddresses() {
      return addresses;
   }
   public void setAddresses(Set<Address> addresses) {
      
      /*
       * comment below code for recreating - delete on select - behaviour 
       */

      this.addresses = addresses;
   }




Code:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping   package="hib.example.model.pojo.bean">

    <class name="Person" table="PERSON">
   
   
        <id name="slNo" column="sl_no">
            <generator class="increment"/>
        </id>
   
<!--       <property update="false" name="name"  column="name"/>-->
       <property name="name"  column="name"/>
       <property name="age" column="age"/>

       <one-to-one name="address" class="hib.example.model.pojo.bean.Address"
             cascade="save-update" fetch="join" />

       <set name="addresses" table="PersonAddress">
           <key column="person_id"/>
          
           <many-to-many column="address_id"
               unique="true"
               class="hib.example.model.pojo.bean.Address"/>
       </set>

    </class>

</hibernate-mapping>



In any case I hope this helps some one!

Regards
Ravi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.