Hibernate version: 3.2
Hi,
I have a parent-child relationship between 2 tables CHARGE and
REMARK (REMARK references CHARGE with an ON DELETE CASCADE
foreign key), here is an excerpt to Charge.hbm.xml:
~<list access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.ListAccessor"
~ cascade="all" inverse="true"
~ name="Remark"
~ table="Charge_Remark">
~
~ <key on-delete="cascade">
~ <column name="Charge_Remark_Hjid"/>
~ </key>
~
~ <list-index>
~ <column name="Charge_Remark_Hjindex"/>
~ </list-index>
~ <one-to-many class="my.package.Remark"/>
~
~</list>
On line 2 if I remove 'inverse="true"' we ALWAYS get the following error:
# junit.framework.TestListener: addError(testUnmarshal, only inverse one-to-many \
# associations may use on-delete="cascade": my.package.Charge.Remark)
In org.hibernate.mapping.Collection we indeed found the conditions
through which this error is raised:
~ if ( getKey().isCascadeDeleteEnabled() && ( !isInverse() || !isOneToMany() ) ) {
~ throw new MappingException(
~ "only inverse one-to-many associations may use on-delete=\"cascade\": "
~ ...
We HAVEN'T declared the inverse many-to-one in Remark.hbm.xml
mapping file, so how come we have to add 'inverse="true"' in order
for our tests to run fine ??
Obviously from the moment on you use a one-to-many association,
IT MUST be inverse as well (even if the corresponding many-to-one
on the other side is not explicitly specified) or there's something I've
missed ???
(as !isInverse and !isOneToMany BOTH have to be false for the condition
not to be met - eg apparently these 2 one-to-many/inverse properties
are inforced EVEN IF THERE IS NO many-to-one prop defined on the
other end of the relationship -?-)
Thanks a lot in advance,
Seb
|