[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4008) Hibernate may generate gap or duplicate list index when do cascade saveOrUpdate

LC (JIRA) noreply at atlassian.com
Thu Jul 2 03:14:18 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4008?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33512#action_33512 ] 

LC commented on HHH-4008:
-------------------------

"When do find by id c5 is missing. " - I mean when use PDAO.findById(),  p come back with c1, c2, c4. 

> Hibernate may generate gap or duplicate list index when do cascade saveOrUpdate
> -------------------------------------------------------------------------------
>
>                 Key: HHH-4008
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4008
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.3.2
>         Environment: WindowsXP. Java 1.5.14. Spring 2.5.6, Junit 3.8.1. Sybase12.5
>            Reporter: LC
>            Priority: Blocker
>
> Say we have ParentTable(p_id, etc) ChildTable(c_id, p_id, listindex) 
> Parent{ 
>     id 
>     Arraylist children; 
>     ... properties 
> } 
> Child{ 
>    id 
>    properties 
> } 
> mapping: 
> Parent.hbm.xml 
> <class name="Parent" table="ParentTable"> 
>          <id name="id" type="java.lang.Long"> 
>             <column name="p_id" /> 
>             <generator class="native" /> 
>         </id> 
>         <list name="children" cascade="all-delete-orphan"> 
>          <key column="p_id" not-null="true" update="false"/> 
> <list-index> 
>          <column name="list_index"/> 
>          </list-index> 
>          <one-to-many class="Child"/> 
>         </list> 
> </class> 
> Child.hbm.xml 
> <class name="Child" table="ChildTable"> 
>         <id name="id" type="java.lang.Long"> 
>             <column name="c_id"/> 
>             <generator class="native"/> 
>         </id> 
> </class> 
> DAO 
> PDAO extends HibernateDaoSupport{ 
>     ...... 
>     public void saveAndUpdate(Parent instance){ 
>         getHibernateTemplate().saveOrUpdate(instance); 
>     } 
>     ...... 
> } 
> Test case: 
> Parent p = new Parent(); 
> p.setChildren(new Arraylist()); 
> Child c1 = new Child(); 
> Child c2 = new Child(); 
> Child c3 = new Child(); 
> Child c4 = new Child(); 
> p.getChildren().add(c1); 
> p.getChildren().add(c2); 
> p.getChildren().add(c3); 
> p.getChildren().add(c4); 
> pDAO.saveAndUpdate(p);// now database have c1(list_index 0),c2(list_index1),c3(list_index2),c4(list_index3) all get saved and looks fine. 
> p.getChildren.remove(c3); 
> pDAO.saveAndUpdate(p);// now c3 get removed. database have c1(list_index 0),c2(list_index1), c4(list_index3). Here we get a gap. 
> Child c5 = new Child(); 
> p.getChildren().add(c5); 
> pDAO.saveAndUpdate(p);// now database have c1(list_index 0),c2(list_index1), c4(list_index3), c5(list_index3). Here we get a gap and a duplicate. 
> From this point. the dao can't do anything with p anymore and the data get cruptted. 
> When do find by id c5 is missing.
> I think this is a quite common case that something hibernate should be able to handle and it shouldn't leave gap and generate duplicate list_index. 
> Is there anyway to fix it in Hibernate? 
> Thank you very much. 

-- 
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

        



More information about the hibernate-issues mailing list