Ola,
Ao executar um delete (que exclui o pai e o filho ao mesmo tempo), o hibernate esta lançando a seguinte exception:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
Abaixo o código e os mapeamentos. Obs: A pesquisa funciona sem erros.
Session session = ConectaHibernate.getSession();
TipoDocumentoORM tip = (TipoDocumentoORM)session.get(TipoDocumentoORM.class,new Integer(tipodocumento));
Transaction tx = session.beginTransaction();
session.delete(tip);
session.flush();
tx.commit();
session.close();
O erro da no “flush”… abaixo os mapeamentos …
Classe “Pai”
<?xml version=“1.0”?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”>
<hibernate-mapping package=“com.porto.portoviewer.orm”>
<class name=“TipoDocumentoORM” table=“jdckdoctip” dynamic-update=“true” lazy=“false”>
<id column=“doctipcod” name=“codigoTipoDocumento” type=“int”/>
<property column=“doctipdes” name=“descricaoTipoDocumento” not-null=“true” type=“string”/>
<property column=“caddat” name=“dataCadastro” not-null=“true” type=“java.util.Date”/>
<property column=“dsctmp” name=“tempoDisco” not-null=“true” type=“int”/>
<property column=“arqrep” name=“pathDisco” not-null=“true” type=“string”/>
<set name="chavesTipoDocumento"
lazy="false"
inverse="false"
outer-join="false"
cascade="all"
order-by=“chvcod”
>
<key>
<column name=“doctipcod” />
</key>
<one-to-many class=“ChavePesquisaORM” />
</set>
</class>
</hibernate-mapping>
Classe “FILHA”
<?xml version=“1.0”?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”>
<hibernate-mapping package=“com.porto.portoviewer.orm”>
<class name=“ChavePesquisaORM” table=“jdckdocchv” dynamic-update=“true” lazy=“false”>
<composite-id >
<key-many-to-one name=“tipoDocumento” class=“TipoDocumentoORM” column=“doctipcod” />
<key-property name=“codigoChave” column=“chvcod” type=“int”/>
</composite-id>
<property column=“chvnom” name=“nomeChave” not-null=“true” type=“string”/>
</class>
</hibernate-mapping>