Heya,
I'm trying to map this FilterChain 1 <---> 0..* AbstractFilter
using a list, because filter order does matter.
My problem is that my list-index is not automaticaly managed by hibernate, which result in when i try to add a concreat filter to my list and save the FilterChain the forder column is always set to 0, which break the list semantic.
Hibernate version:3.2.0ga
Mapping documents:
FilterChain.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="fr.xx.model.FilterChain"
table="FILTERCHAIN"
dynamic-update="true"
>
<id
name="id" column="id" type="java.lang.Long" unsaved-value="0">
<generator class="sequence"/>
</id>
<property name="comment" type="text" update="true" insert="true" column="comment" not-null="false"/>
<property name="date" type="java.util.Date" update="true" insert="true" column="date" not-null="true"/>
<!-- from http://forum.hibernate.org/viewtopic.php?t=943384 -->
<list name="filters"
lazy="true"
inverse="false"
cascade="all,delete-orphan"
>
<key column="chain_id" not-null="true" update="false"/>
<list-index column="forder" />
<one-to-many class="fr.xx.model.AbstractFilter"/>
</list>
<property name="name" type="java.lang.String" update="true" insert="true" column="name" not-null="true" unique="true"/>
<property name="owner" type="java.lang.String" update="true" insert="true" column="owner" not-null="true"/>
</class>
</hibernate-mapping>
AbstractFilter.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class name="fr.xx.model.AbstractFilter" table="FILTER" discriminator-value="A">
<cache usage="read-write" />
<id name="id" column="id" type="java.lang.Long" unsaved-value="0">
<generator class="sequence"/>
</id>
<discriminator column="TYPE" type="string" />
<many-to-one
name="key"
class="fr.xx.model.DefaultLabelKey"
cascade="none"
fetch="select"
update="true"
insert="true"
column="key_id"
not-null="true"
lazy = "false"
/>
<!-- from http://forum.hibernate.org/viewtopic.php?t=943384 -->
<many-to-one name="chain"
column="chain_id"
class="fr.xx.model.FilterChain"
not-null="true"
insert="false"
update="false"
/>
<!-- read-only property used by hibernate to manage list order -->
<property name="forder" column="forder" type="int" insert="false" update="false" not-null="true"/>
<subclass
name="fr.xx.model.GroupFilter"
discriminator-value="G"
/>
<subclass
name="fr.xx.model.ReduceFilter"
discriminator-value="R"
>
<property name="revert" type="boolean" update="true" insert="true" column="revert"/>
<property name="value" type="java.lang.String" update="true" insert="true" column="value" />
</subclass>
</class>
</hibernate-mapping>
Name and version of the database you are using: PostgreSQL 8.0The generated SQL (show_sql=true):Code:
Hibernate: insert into FILTER (key_id, chain_id, forder, revert, value, TYPE, id) values (?, ?, ?, ?, ?, 'R', ?)
Hibernate: update FILTERCHAIN set comment=?, date=?, name=?, owner=? where id=?
Hibernate: update FILTER set key_id=?, revert=?, value=? where id=?
Hibernate: update FILTER set key_id=?, revert=?, value=? where id=?
relevant Database SchemaCode:
...
create table FILTER (id int8 not null, TYPE varchar(255) not null, key_id int8 not null, chain_id int8 not null, forder int4 not null, revert bool, value varchar(255), primary key (id));
create table FILTERCHAIN (id int8 not null, comment text, date timestamp not null, name varchar(255) not null unique, owner varchar(255) not null, primary key (id));
alter table FILTER add constraint FK7B9BBF78599119ED foreign key (key_id) references LABELKEY;
alter table FILTER add constraint FK7B9BBF78CFBD0B48 foreign key (chain_id) references FILTERCHAIN;