Dear Friends.
I have 3 tables.
One of this tables is a join among the two others.
Follow the hbms:
TABLE 1
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="br.com.datamidia.pao.vo">
<class name="Pesquisa" table="T051_PESQUISA">
<id name="id" type="long" column="CD_PESQUISA">
<generator class="br.com.datamidia.pao.key.GenericKeyProvider">
<param name="table">Pesquisa</param>
</generator>
</id>
<property name="dePesquisa" column="DE_PESQUISA" type="string"
not-null="true" length="50" />
<property name="cdCampanhaEpiphany"
column="CD_CAMPANHA_EPIPHANY" type="string" not-null="false"
length="50" />
<property name="deObsPesquisa" column="DE_OBS_PESQUISA"
type="string" not-null="false" length="250" />
<property name="dtInicialPesquisa" column="DT_INICIAL_PESQUISA"
type="date" not-null="true" length="7" />
<property name="dtTerminoPesquisa" column="DT_TERMINO_PESQUISA"
type="date" not-null="false" length="7" />
<property name="cdScript" column="CD_SCRIPT" type="integer"
not-null="false" length="5" />
<property name="deHardcodePesquisa"
column="DE_HARDCODE_PESQUISA" type="string" not-null="false"
length="15" />
<property name="dtInclusao" column="DT_INCLUSAO" type="date"
not-null="true" length="7" update="false" />
<property name="cdUsuarioInclusao" column="CD_USUARIO_INCLUSAO"
type="long" not-null="true" length="10" update="false" />
<property name="dtAlteracao" column="DT_ALTERACAO" type="date"
not-null="false" length="7" insert="false"/>
<property name="cdUsuarioAlteracao"
column="CD_USUARIO_ALTERACAO" type="long" not-null="false"
length="10" insert="false" />
<property name="dtMigracaoMart" column="DT_MIGRACAO_MART"
type="date" not-null="false" length="7" insert="false" />
<many-to-one name="regraPontuacao" column="CD_REGRA_PONTUACAO"
class="br.com.datamidia.pao.vo.RegraPontuacao" cascade="save-update" />
<set name="pergunta" lazy="false" cascade="all">
<key column="CD_PESQUISA"/>
<one-to-many class="br.com.datamidia.pao.vo.Pergunta"/>
</set>
<set name="canalPesquisa" lazy="false" cascade="all">
<key column="CD_PESQUISA"/>
<one-to-many class="br.com.datamidia.pao.vo.CanalPesquisa"/>
</set>
</class>
</hibernate-mapping>
TABLE 2(THE JOIN TABLE)
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="br.com.datamidia.pao.vo">
<class name="CanalPesquisa" table="T055_CANAL_PESQUISA">
<composite-id name="id"
class="br.com.datamidia.pao.key.CanalPesquisaKey">
<key-many-to-one name="tipoCanal" column="CD_TIPO_CANAL" />
<key-many-to-one name="pesquisa" column="CD_PESQUISA" />
</composite-id>
<property name="dtInclusao" column="DT_INCLUSAO" type="date"
not-null="true" length="7" />
<property name="cdUsuarioInclusao" column="CD_USUARIO_INCLUSAO"
type="long" not-null="true" length="10" />
<property name="dtAlteracao" column="DT_ALTERACAO" type="date"
not-null="false" length="7" />
<property name="cdUsuarioAlteracao"
column="CD_USUARIO_ALTERACAO" type="long" not-null="false"
length="10" />
<property name="dtMigracaoMart" column="DT_MIGRACAO_MART"
type="date" not-null="false" length="7" />
</class>
</hibernate-mapping>
TABLE 3
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="br.com.datamidia.pao.vo">
<class name="TipoCanal" table="T535_TIPO_CANAL">
<id name="id" type="long" column="CD_TIPO_CANAL">
<generator
class="br.com.datamidia.pao.key.GenericKeyProvider">
<param name="table">TipoCanal</param>
</generator>
</id>
<property name="deTipoCanal" column="DE_TIPO_CANAL"
type="string" not-null="true" length="35" />
<property name="deTipoCanalAbrev" column="DE_TIPO_CANAL_ABREV"
type="string" not-null="true" length="10" />
<property name="dtInclusao" column="DT_INCLUSAO" type="date"
not-null="true" length="7" />
<property name="cdUsuarioInclusao" column="CD_USUARIO_INCLUSAO"
type="long" not-null="true" length="10" />
<property name="dtAlteracao" column="DT_ALTERACAO" type="date"
not-null="false" length="7" />
<property name="cdUsuarioAlteracao"
column="CD_USUARIO_ALTERACAO" type="long" not-null="false"
length="10" />
<property name="dtMigracaoMart" column="DT_MIGRACAO_MART"
type="date" not-null="false" length="7" />
<set name="canalPesquisa" inverse="true" cascade="save-update">
<key column="CD_TIPO_CANAL"/>
<one-to-many class="br.com.datamidia.pao.vo.CanalPesquisa"/>
</set>
</class>
</hibernate-mapping>
I'm trying to update with the follow code:
public Long savePesquisa(Pesquisa pesquisa) throws SystemException, BusinessException {
Long ret = null;
if (pesquisa.getId() != null) { // alteração
Pesquisa pSession = getPesquisaByPK(pesquisa.getId()); // pego o pesquisa na sessão do hibernate.
if (pSession == null) {
throw new SystemException("Não foi possível alterar a Pesquisa");
}
try {
PropertyUtilsExt.copyProperties(pSession,pesquisa);
hibernateDaoPesquisa.save(pSession);
ret = pSession.getId();
} catch(Exception e) {
throw (SystemException)new SystemException("Não foi possível alterar a Pesquisa").initCause(e);
}
} else {
hibernateDaoPesquisa.save(pesquisa);
ret = (Long)hibernateDaoPesquisa.getSession().getIdentifier(pesquisa);
}
return ret;
}
but i always get this erro: can not update null to CD_PESQUISA field in CanalPesquisa.
|