0
votes

I'm facing a problem with class mapping in hibernate. I'm trying to make a many-to-one relationship using a composite-id. and the mapping is returning

Repeated column in mapping for entity: br.com.is.isenterprise.cre.model.ClienteRegraIcmsMap column: EMPRESAID (should be mapped with insert="false" update="false")

but if I set the many-to-one relationship to insert =" false " and update =" false I can not insert the id of regraIcmsSubistituta in the database. follows the hbm files.

RegraIcms.hbm.xml

<hibernate-mapping package="br.com.is.isenterprise.efi.model">

    <class name="RegraIcms" table="REGRAICMS">
        <composite-id name="cid" class="br.com.is.isenterprise.efi.model.RegraIcmsId">
            <key-property name="empCod" type="integer" column="EMPCOD"/>
            <key-property name="idRegraIcms" type="integer" column="IDREGRAICMS"/>
        </composite-id>

        <property name="descricao" type="string" column="DESCRICAO" access="field"/>
        <property name="aplicacao" type="integer" column="APLICACAO" access="field"/>   

    </class>

</hibernate-mapping>

ClienteRegraIcmsMapId.hbm.xml

    <class name="ClienteRegraIcmsMap" table="CLIENTEREGRAICMSMAP">
        <composite-id name="cid" class="br.com.is.isenterprise.cre.model.ClienteRegraIcmsMapId">
            <key-many-to-one name="cliente"  column="CLIENTEID" class="br.com.is.isenterprise.cre.model.Cliente" access="field" lazy="false"/>
            <key-many-to-one name="regraIcms" class="br.com.is.isenterprise.efi.model.RegraIcms" access="field" lazy="false">
                <column name="EMPRESAID"/>      
                <column name="REGRAICMSID"/>
            </key-many-to-one>      
        </composite-id>
        <version name="versao" type="integer" column="VERSAO"/>
        <many-to-one name="regraIcmsSubstituta" class="br.com.is.isenterprise.efi.model.RegraIcms" access="field" lazy="false">
            <column name="EMPRESAID"/>      
            <column name="REGRAICMSSUBSTITUTAID"/>
        </many-to-one>
    </class>
</hibernate-mapping>
1

1 Answers

0
votes

You're trying to use the same column (EMPRESAID) for two different things, the primary key as well as the many-to-one relation.

That's not gonna work (except with insertable = "false", as you mentioned)

If it's possible use a separate column for EMPRESAID in one of the mappings.