Hi! I'm using NH 1.2.0 Beta 2.
I have the following tables:
Table1: Cargo
Fields: EMP_ID, CODIGO, DESCRICAO. TIPO
Table 2: TipoCargo
Fields: EMP_ID, CODIGO, DESCRICAO
I want to map a many-to-one association between Cargo and TipoCargo.
I'm trying this:
Table Cargo
Code:
...
<class name="Cargo" table="cargo" lazy="true">
<composite-id access="field" unsaved-value="any">
<key-property name="EmpId" column="EMP_ID" type="Int32" />
<key-property name="Codigo" column="CODIGO" type="Int32" />
</composite-id>
<property column="DESCRICAO" type="String" name="Descricao" />
<!-- Tipo -->
<many-to-one class="TipoCargo" name="Tipo" cascade="none">
<column name="EMP_ID" />
<column name="TIPO" />
</many-to-one>
</class>
...
Table TipoCargo
Code:
<class name="TipoCargo" table="tipocargo" lazy="true">
<composite-id access="field">
<key-property name="EmpId" column="EMP_ID" type="Int32" />
<key-property name="Codigo" column="CODIGO" type="Int32" />
</composite-id>
<property column="DESCRICAO" type="String" name="Descricao" />
</class>
...
As you can see, the association many-to-one is into the Cargo mapping. When I try to INSERT (Save) a Cargo object, I'm getting the following error:
Quote:
NHibernate.ADOException: could not insert: [xxx.DTO.Cargo#xxx.DTO.Cargo] ---> MySql.Data.MySqlClient.MySqlException: Coluna 'EMP_ID' especificada duas vezes
The SQL generated is something like this:
Quote:
INSERT INTO cargo (emp_id, codigo, descricao, emp_id, tipo) VALUES (1, 1, 'teste', 1, 1)
As you can see, the EMP_ID field is duplicated! I think this is because the association, right?
So, how can I do it? Any Idea?
Tks!