-->
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: Behaviour of dynamic-component
PostPosted: Wed Mar 30, 2005 5:48 am 
Newbie

Joined: Fri Feb 04, 2005 6:43 am
Posts: 2
When using a mapping that contains a dynamic-component, if an entity is persisted where all the entries of the component are null, when the entity is loaded hibernate sets the entire component map to null.

Is this the expected behaviour? Is there a reason that an empty HashMap is not used instead?

Hibernate version: 3.0rc1-3.0cvs20050324

Mapping document:
Code:
<hibernate-mapping>
    <class name="eg.Bean" table="BEANS">
        <id name="id" column="BEANID" type="integer">
            <generator class="native"/>
        </id>
      <dynamic-component name="properties">
         <property name="test01" column="TEST01" type="string" length="64"/>
      </dynamic-component>
    </class>
</hibernate-mapping>


Java files:
Code:
public class Bean {
   private Integer id;
   private Map properties = new HashMap();
   
   public Integer getId() { return id; }
   public void setId(Integer id) { this.id = id; }
   
   public Map getProperties() { return properties; }
   public void setProperties(Map properties) {
      if (properties == null)
         throw new IllegalArgumentException("Why should I be nulled?");
      this.properties = properties;
   }
}

Code:
public class Test {
   public static void main(String[] args) {
      Configuration cfg = new Configuration().configure();
      new SchemaExport(cfg).create(false, true);
      SessionFactory sf = cfg.buildSessionFactory();
      Session s = sf.openSession();
      
      s = sf.openSession();
      Bean b = new Bean();
      s.save(b);
      s.flush();
      s.close();
      Integer id = b.getId();
      
      s = sf.openSession();
      b = (Bean) s.get(Bean.class, id); //This will set properties to null
   }
}


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.