I have one class mapped as a view and I have a method that reads a xls file and using transaction, try to insert the data in the file in another table. When hibernate detects that an object exists and need to update it with the information from the xls, it is giving me an error:
Could not synchronize database state with session.
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch updateCaused by: java.sql.BatchUpdateException: View 'VIEW_ESTOQUE' is not updatable because a field of the view is derived or constant.I donĀ“t know why it is trying to execute the following SQL in a view
Hibernate: update VIEW_ESTOQUE set QTD_ESTOQUE=?, VLR_ESTOQUE=? where COD_DEPENDENCIA=? and COD_ALMOXARIFADO=? and COD_INSUMO_OBRA=?Following is the mapping of the view and the table that the data needs to be recorded/updated
Code:
<hibernate-mapping package="com.ccne.bo">
<class
name="Estoque"
table="VIEW_ESTOQUE"
>
<composite-id>
<key-many-to-one
name="almoxarifado"
class="Almoxarifado"
>
<column name="COD_DEPENDENCIA" />
<column name="COD_ALMOXARIFADO" />
</key-many-to-one>
<key-many-to-one
name="insumoObra"
class="InsumoObra"
>
<column name="COD_INSUMO_OBRA" />
</key-many-to-one>
</composite-id>
<property
name="qtdEstoque"
type="double"
column="QTD_ESTOQUE"
length="18"
/>
<property
name="vlrEstoque"
type="double"
column="VLR_ESTOQUE"
length="19"
/>
<property
name="idtClassificacaoDependencia"
type="java.lang.String"
formula="( select t1.IDT_CLASSIFICACAO from TB_INSUMO_OBRA_DEPENDENCIA t1 where t1.COD_INSUMO_OBRA = COD_INSUMO_OBRA and t1.COD_DEPENDENCIA = COD_DEPENDENCIA )"
/>
</class>
</hibernate-mapping>
Code:
<class name="MovimentoEstoque" table="TB_MOVIMENTO_ESTOQUE">
<id name="numMovimentoEstoque" column="NUM_MOVIMENTO_ESTOQUE">
<generator class="increment"/>
</id>
<property name="datMovimentoEstoque" column="DAT_MOVIMENTO_ESTOQUE" not-null="true" />
<property name="numDocumento" column="NUM_DOCUMENTO" not-null="true" length="20"/>
<property name="qtdMovimentoEstoque" column="QTD_MOVIMENTO_ESTOQUE" not-null="true"/>
<property name="vlrMovimento" column="VLR_MOVIMENTO" not-null="false"/>
<property name="idtTipoMovimento" column="IDT_TIPO_MOVIMENTO" type="java.lang.String" not-null="true" length="1"/>
<property name="idtEntSai" column="IDT_ENT_SAI" not-null="true" length="1"/>
<property name="idtTipoAcerto" column="IDT_TIPO_ACERTO" not-null="false" length="1"/>
<property name="numMovimentoRequisicao" column="NUM_MOVIMENTO_REQ"/>
<property name="desMotivo" column="DES_MOTIVO" length="255" />
<property name="desRequisitante" column="DES_REQUISITANTE" length="200" />
<property name="gerarMedicao" column="GERAR_MEDICAO" />
<property
name="codServicoObra"
type="java.lang.String"
column="COD_SERVICO_OBRA"
insert="false"
update="false"
/>
<property
name="codInsumoObraControlado"
type="java.lang.Integer"
column="COD_INSUMO_OBRA_CONTROLADO"
insert="false"
update="false"
/>
<property
name="idtClassificacaoDependencia"
type="java.lang.String"
formula="( select t1.IDT_CLASSIFICACAO from TB_INSUMO_OBRA_DEPENDENCIA t1 where t1.COD_INSUMO_OBRA = COD_INSUMO_OBRA and t1.COD_DEPENDENCIA = COD_DEPENDENCIA )"
/>
<many-to-one name="insumoObraControlado" class="InsumoObraControlado">
<column name="COD_DEPENDENCIA_CONTROLADO" />
<column name="COD_INSUMO_OBRA_CONTROLADO" />
</many-to-one>
<many-to-one name="fornecedor" class="Fornecedor">
<column name="COD_CGC_CPF" />
<column name="COD_SERIE" />
<column name="COD_CONTROLE" />
</many-to-one>
<many-to-one name="agrupamentoServicoDNC" class="AgrupamentoServicoDNC">
<column name="COD_AGRUPAMENTO_SERVICO_DNC" />
</many-to-one>
<many-to-one name="almoxarifado" class="Almoxarifado" >
<column name="COD_DEPENDENCIA" />
<column name="COD_ALMOXARIFADO" />
</many-to-one>
<many-to-one name="insumoObra" class="InsumoObra">
<column name="COD_INSUMO_OBRA" />
</many-to-one>
<many-to-one name="servicoObra" class="ServicoObra">
<column name="COD_DEPENDENCIA_SERVICO_OBRA" />
<column name="COD_FAMILIA_SERVICO" />
<column name="COD_SERVICO_OBRA" />
</many-to-one>
<many-to-one name="contratoTerceiro" class="ContratoTerceiro">
<column name="NUM_CONTRATO_TERCEIRO" />
</many-to-one>
<many-to-one name="medicao" class="Medicao">
<column name="NUM_MEDICAO" />
</many-to-one>
<!-- bi-directional many-to-one association to TbUniMedida -->
<many-to-one
name="uniMedida"
class="UniMedida"
not-null="false"
insert="true"
update="true"
>
<column name="COD_UNI_MEDIDA" />
</many-to-one>
<many-to-one name="movimentoEstoqueEntrada" class="MovimentoEstoque">
<column name="NUM_MOVIMENTO_ENTRADA" />
</many-to-one>
</class>
</hibernate-mapping>
Does anyone here can help me with this problem? I already spent 2 days on it without success :(
Thanks,
Eduardo Santos