I am using Hibernete 2.1, with HSQLDB 1.7.1.
Here is the code that is causing me a problem. It is intended simply to remove a certain child from a collection. For testing purposes this particular snippet is locating the first child and deleting it. At the end of this, the child is still there. If I follow it in the debugger, the first thing that happens inside the 'remove' method, is some kind of a Set.Add method, which I don't understand and at any rate, after the remove method returns if I look at the collection in the debugger, the child has not been renoved... Can you see what's wrong?
Thanks!
Code:
// ensure that 'group' is updated
session = sessions.openSession()
transaction = session.beginTransaction();
session.update(group);
// get first channel in collection
Collection channels = group.getChannelGroup().getChannels();
Iterator iter = channels.iterator();
channel = (Channel) iter.next();
transaction.commit();
session.flush();
session.close();
session = null;
transaction = null;
// Now actually do the remove
session = sessions.openSession()
transaction = session.beginTransaction();
group.remove(channel);
transaction.commit();
session.flush();
session.close();
session = null;
transaction = null;
When I run through this code, and check the number of children that group has, it doesn't appear to be actually removing the child.
Here is the mapping for 'group':
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="de.nava.informa.impl.hibernate.ChannelGroup"
table="CHANNEL_GROUPS"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="intId"
column="CHANNEL_GROUP_ID"
type="integer"
>
<generator class="native">
</generator>
</id>
<property
name="title"
type="java.lang.String"
update="true"
insert="true"
column="TITLE"
not-null="true"
/>
<set
name="channels"
table="CAT_GROUP_CHANNEL"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="GROUP_ID"
/>
<many-to-many
class="de.nava.informa.impl.hibernate.Channel"
column="CHANNEL_ID"
outer-join="auto"
/>
</set>
<many-to-one
name="parent"
class="de.nava.informa.impl.hibernate.ChannelGroup"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="PARENT_ID"
/>
<bag
name="children"
lazy="true"
inverse="false"
cascade="none"
order-by="CHANNEL_GROUP_ID"
>
<key
column="PARENT_ID"
/>
<one-to-many
class="de.nava.informa.impl.hibernate.ChannelGroup"
/>
</bag>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ChannelGroup.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
And here is the mapping for 'Channel':
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="de.nava.informa.impl.hibernate.Channel"
table="CHANNELS"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="intId"
column="CHANNEL_ID"
type="integer"
>
<generator class="native">
</generator>
</id>
<property
name="title"
type="java.lang.String"
update="true"
insert="true"
column="TITLE"
not-null="true"
/>
<property
name="description"
type="java.lang.String"
update="true"
insert="true"
column="DESCRIPTION"
/>
<property
name="locationString"
type="string"
update="true"
insert="true"
column="LOCSTRING"
/>
<property
name="site"
type="java.net.URL"
update="true"
insert="true"
column="SITE"
/>
<property
name="creator"
type="java.lang.String"
update="true"
insert="true"
column="CREATOR"
/>
<property
name="publisher"
type="java.lang.String"
update="true"
insert="true"
column="PUBLISHER"
/>
<property
name="language"
type="java.lang.String"
update="true"
insert="true"
column="LANGUAGE"
/>
<property
name="formatString"
type="string"
update="true"
insert="true"
column="FORMAT"
/>
<bag
name="items"
table="ITEMS"
lazy="false"
inverse="false"
cascade="all"
>
<key
column="CHANNEL_ID"
/>
<one-to-many
class="de.nava.informa.impl.hibernate.Item"
/>
</bag>
<many-to-one
name="image"
class="de.nava.informa.impl.hibernate.Image"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="IMAGE_ID"
not-null="false"
/>
<many-to-one
name="textInput"
class="de.nava.informa.impl.hibernate.TextInput"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="TEXTINPUT_ID"
not-null="false"
/>
<property
name="copyright"
type="java.lang.String"
update="true"
insert="true"
column="COPYRIGHT"
/>
<property
name="rating"
type="java.lang.String"
update="true"
insert="true"
column="RATING"
/>
<many-to-one
name="cloud"
class="de.nava.informa.impl.hibernate.Cloud"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="CLOUD_ID"
not-null="false"
/>
<property
name="generator"
type="java.lang.String"
update="true"
insert="true"
column="GENERATOR"
/>
<property
name="docs"
type="java.lang.String"
update="true"
insert="true"
column="DOCS"
/>
<property
name="ttl"
type="int"
update="true"
insert="true"
column="TTL"
/>
<bag
name="categories"
table="CAT_CHANNEL_LINK"
lazy="true"
inverse="false"
cascade="none"
>
<key
column="CHANNEL_ID"
/>
<many-to-many
class="de.nava.informa.impl.hibernate.Category"
column="CATEGORY_ID"
outer-join="auto"
/>
</bag>
<property
name="lastUpdated"
type="java.util.Date"
update="true"
insert="true"
column="LAST_UPDATED"
/>
<property
name="lastBuildDate"
type="java.util.Date"
update="true"
insert="true"
column="LAST_BUILD_DATE"
/>
<property
name="pubDate"
type="java.util.Date"
update="true"
insert="true"
column="PUB_DATE"
/>
<property
name="updatePeriod"
type="java.lang.String"
update="true"
insert="true"
column="UPDATE_PERIOD"
/>
<property
name="updateFrequency"
type="int"
update="true"
insert="true"
column="UPDATE_FREQUENCY"
/>
<property
name="updateBase"
type="java.util.Date"
update="true"
insert="true"
column="UPDATE_BASE"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Channel.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>