From: Sanjiv J. (JIRA) <no...@at...> - 2006-07-06 18:13:57
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HB-175?page=comments#action_23558 ] Sanjiv Jivan commented on HB-175: --------------------------------- I think this is a serious bug. Gavin wrote "This is intended functionality (for performance we don't include the discriminator). You can force the behaviour you desire by adding a where attribute the the collection mapping." The problem with simply adding a "where" attribute on the collection mapping is that it does limit the objects being placed in the collection to be of the right type. However if the collection mapped to one sublass (say subChilds_1) is made empty (when the user wants to delete all associations of this subclass), hibernate issues a delete command that delete all subclass rows for the given parent. For example "delete from Child child0_ where child0_.parent_id=?" Hibernate should to be aware of the subclass discriminator associations and add the appropriate "where discriminator_column = ?" for both reads and writes. Can you explain the performace reasongs why the discriminator isn't being added? AFAICT is just ant additional where conditional, which is how discriminator based subclass mapping works for regular loads of subclasses. > One-to-many association does not correctly discriminate when a subclass is specified > ------------------------------------------------------------------------------------ > > Key: HB-175 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HB-175 > Project: Hibernate2 > Type: Bug > Components: core > Versions: 2.0.1 > Environment: Gentoo Linux, Sun Java 1.4.1 > Reporter: Peachawat Peachavanish > > > When using one-to-many association from 'Parent' to 'SubChild_1' and 'SubChild_2' where 'SubChild_1' and 'SubChild_2' are subclasses of 'Child', the generated SQL for hydrating a 'Parent' does not appropriate include 'where' clause to discriminate 'SubChild_1' or 'SubChild_2'. > Class Declaration > ================= > 'Child.java' > public abstract class Child{} > 'SubChild_1.java' > public class SubChild_1 extends Child {} > 'SubChild_2.java' > public class SubChild_2 extends Child {} > 'Parent.java' > public class Parent { > private List subChilds_1 = new ArrayList(); > private List subChilds_2 = new ArrayList(); > } > Mapping > ======= > 'Child.hbm.xml' > <?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="Child" discriminator-value="_"> > <id name="id"> > <generator class="native"/> > </id> > <discriminator column="CHILDTYPE"/> > <property name="aProperty"/> > <subclass name="SubChild_1" discriminator-value="1"/> > <subclass name="SubChild_2" discriminator-value="2"/> > </class> > </hibernate-mapping> > 'Parent.hmb.xml' > <?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="Parent"> > <id name="id"> > <generator class="native"/> > </id> > <property name="aProperty"/> > <list name="subChilds_1" lazy="false" cascade="all"> > <key column="parent_id"/> > <index column="idx"/> > <one-to-many class="SubChild_1"/> > </list> > <list name="subChilds_2" lazy="false" cascade="all"> > <key column="parent_id"/> > <index column="idx"/> > <one-to-many class="SubChild_2"/> > </list> > </class> > </hibernate-mapping> > Generated SQL when perform session.find() > ========================================= > Hibernate: select child0_.id as id__, child0_.idx as idx__, child0_.id as id from Child child0_ where child0_.parent_id=? > There is no 'where CHILDTYPE=?' discriminating clause. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |