-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cannot remove a entity from a collection. [RESOLVED]
PostPosted: Thu Mar 13, 2008 4:54 pm 
Newbie

Joined: Wed Nov 07, 2007 2:46 pm
Posts: 6
When i try:

Code:
regra = grupo.getRegras().remove(i);
tx = HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
factory.getRegraDAO().delete(regra);
factory.getGrupoDAO().update(grupo);
tx.commit();


I receive the follow exception:

Code:
Exception occurred during event dispatching:
org.hibernate.exception.GenericJDBCException: could not update collection rows: [especialista.regra.Grupo.regras#1]


Maps:

Code:
<class name="especialista.regra.Regra"
           table="REGRAS">
       
        <id
            name="id"
            column="REGRA_ID">
            <generator class="increment"/>
        </id>
       
        <many-to-one
            name="grupo"
            class="especialista.regra.Grupo"
            not-null="true"
            column="GRUPO_ID"/>
       
        <many-to-one
            name="conclusao"
            class="especialista.regra.Clausula"
            cascade="all"
            not-null="true"
            lazy="false"/>
       
        <list name="antecedentes" cascade="all" lazy="false">
            <key column="REGRA_ID"/> 
            <list-index base="0"/>
            <one-to-many class="especialista.regra.Clausula"/>
        </list>
       
        <property name="nome" column="NOME_REGRA"/>
        <property name="descricao" column="DESCRICAO_REGRA"/>         
        <property name="confianca" column="CONFIANCA_REGRA"/>   
        <property name="tipo" column="TIPO_REGRA"/>
        <property name="estado" column="ESTADO_REGRA"/>         
    </class>


Code:
<class name="especialista.regra.Grupo"
           table="GRUPOS">
       
        <id
            name="id"
            column="GRUPO_ID">
            <generator class="increment"/>
        </id>
       
        <list name="regras">
            <key column="GRUPO_ID"/>
            <list-index base="0"/>
            <one-to-many class="especialista.regra.Regra"/>
        </list>
       
        <property name="nome" column="NOME_GRUPO"/>               
       
    </class>


Anyone can help me please?

Davi


Last edited by heatcold on Fri Mar 14, 2008 10:05 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Cannot remove a entity from a collection. [RESOLVED]
PostPosted: Fri Mar 14, 2008 10:04 am 
Newbie

Joined: Wed Nov 07, 2007 2:46 pm
Posts: 6
I resolve this changing the map:

Code:
<list name="regras" cascade="delete">
            <key column="GRUPO_ID"/>
            <list-index base="0"/>
            <one-to-many class="especialista.regra.Regra"/>
</list>


Code:
<many-to-one
            name="grupo"
            class="especialista.regra.Grupo"
            cascade="save-update"
            not-found="ignore"
            column="GRUPO_ID"/>


Code:
tx = HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
        List grupos = factory.getGrupoDAO().list();
        Grupo grupo = (Grupo) grupos.get(0);
       
        tx = HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
        Regra regra = grupo.getRegras().remove(0);
        //factory.getRegraDAO().delete(regra);
        //factory.getGrupoDAO().update(grupo);
        tx.commit();


works!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.