On the remote chance that there was actually a bug in this,
I took your mapping document, ported it to the 1.0 mapping
DTD, ran CodeGenerator to produce the persistent classes,
ran your code against Hibernate2. I did not observe the
behaviour you report (exactly two insert statements).

I suggest that you re-check your code, since as I said
in my last mail, this is not how Hibernate behaves.

Especially check to make sure that the save() call does not
somehow change the state of your objects. (eg. setId() alters
the state or something strange like that.)

I suggest you use CodeGenerator to do the same thing I did....

Gavin


> On Sun, 12 Jan 2003 17:32:16 +1100 (EST), "Gavin King"
> <[EMAIL PROTECTED]> said:
>> > am i doing something wrong or this is a known limitation?
>>
>> You must be doing something wrong (though I'm not quite sure
>> what). A bidirectional one-to-many association with
>> readonly="true" should require only 1 SQL statement per
>> element.
>>
>>
>> Are you sure that you aren't
>>
>> (a) flushing the Session between saving the children and adding
>> them to the collections
>>
>> (b) missing the readonly attribute of the collection mapping
>
> here's how the mapping looks like:
>
>       <class name="Foo" table="foo">
>               <id name="id">
>                       <generator class="vm.hex"/>
>               </id>
>               <property name="title"/>
>               <bag role="items"  readonly="true" cascade="all">
>                       <key column="foo_id"/>
>                       <one-to-many class="Bar"/>
>               </bag>
>        </class>
>
>       <class name="Bar" table="bar">
>               <id name="id">
>                       <generator class="vm.hex"/>
>               </id>
>               <many-to-one name="origin" class="Foo" column="foo_id"/>
>               <property name="title"/>
>       </class>
>
> the save code is really simple:
>
>         // ... set up Foo foo, with 1 Bar child, child has parent set as
> origin
>
>       Session s = this.sessionFactory.openSession();
>       s.save(foo);
>       s.flush();
>       s.connection().commit();
>       s.close();
>
>
> what is the problem with the above? i would like to understand the logic
> that makes hibernate do an extra UPDATE...
>
> thx,
>
>    viktor
> --
>
>   [EMAIL PROTECTED]
>
> --
> http://fastmail.fm - A fast, anti-spam email service.





-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to