-->
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.  [ 4 posts ] 
Author Message
 Post subject: Adding new object to lazy list not updates object's index?
PostPosted: Wed Nov 19, 2003 11:01 am 
Newbie

Joined: Fri Aug 29, 2003 3:31 pm
Posts: 6
Hi.

I have those classes:


Code:
<hibernate-mapping>

  <class name="my.faq.Topic" table="faq_topic">
    <id name="id" column="ID" type="long" unsaved-value="any">
      <generator class="hilo">
        <param name="table">hibernate_unique_key</param>
        <param name="column">next_faq_topic</param>
      </generator>
    </id>
    <property name="name" column="name" type="string"/>
    <list name="units" cascade="all" table="faq_unit" lazy="true">
      <key column="topic_id"/>
      <index column="index1"/>
      <one-to-many class="my.faq.Unit"/>
    </list>
  </class>

  <class name="my.faq.Unit" table="faq_unit">
    <id name="id" column="ID" type="long" unsaved-value="any">
      <generator class="hilo">
        <param name="table">hibernate_unique_key</param>
        <param name="column">next_faq_unit</param>
      </generator>
    </id>
    <property name="topicId" column="topic_id" type="long"/>
    <property name="index" column="index1" type="int"/>
  </class>

</hibernate-mapping>


Now i do the following:

Code:
Unit firstUnit = new Unit();
Session sess = getNewSession();
Topic topic = sess.open(...);
topic.getUnits().add(firstUnit);
sess.update(topic);

System.out.println(firstUnit.getIndex()); // returns 0

sess.close();

<some other code>

Unit secondUnit = new Unit();
sess = getNewSession();
Topic topic = sess.open(...);
topic.getUnits().add(secondUnit);
sess.update(topic);

System.out.println(secondUnit.getIndex()); // returns also 0!
sess.update(secondUnit); // persists secondUnit with index=0

sess.close();


So, i get two objects persisted with index 0, and when i load topic, list contains only one of those objects.

If i won't update secondUnit directly and close the session, it gets index 1.

The question: is such behaviour ok, and i need to initialize lazy list before add object to it, or there is a some kind of bug?

Thanks in advance.

P.S. sorry for my english.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 11:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Eh? Hibernate does not set property values when you save an object. (Well, except for the version property.)


Top
 Profile  
 
 Post subject: Re: Adding new object to lazy list not updates object's inde
PostPosted: Wed Nov 19, 2003 11:15 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
Why do you "update" the first "Topic"? Has it been saved? To "update" the Topic you need to set it's id. Is it set?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 11:50 am 
Newbie

Joined: Fri Aug 29, 2003 3:31 pm
Posts: 6
Oops. my bad - working day comes to the end and my mind is messed up. Thanks, Gavin!


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

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.