Hi;
I have a problem mapping for this design;
I used
joined-subclass for the first level and
subclass for the second level .
for example I want to add a new invoice sales So the code is: I used a mapping file for each class
Document.hbm.xml:Code:
<hibernate-mapping>
<class name="src.Document" table="DOCUMENT">
<composite-id class="src.IdDocument" name="identifiant">
<key-property column="NUM_DOC" name="numero" />
<key-property column="TYPE_DOC" name="type" />
</composite-id>
<discriminator column="TYPE" type="string" />
...........
...........
</class>
</hibernate-mapping>
DocumentSale.hbm.xml:Code:
<hibernate-mapping>
<joined-subclass name="src.DocumentSale" extends="src.Document" table="DOCUMENT_SALE">
<key property-ref="identifiant">
<column name="NUM_DOC"></column>
<column name="TYPE_DOC"></column>
</key>
<property name="ref" column="REF" type="java.lang.String"/>
...........
...........
</class>
</hibernate-mapping>
InvoiceSale.hbm.xml:Code:
<hibernate-mapping>
<subclass name="src.InvoiceSale" extends="src.DocumentSale"
discriminator-value="INVOICE_SALE">
</subclass>
</hibernate-mapping>
in code java
Code:
InvoiceSale invoice = new InvoiceSale();
//....
Session session = service.getTheSession();
session .saveOrUpdate(invoice );
and this is what appears in the console
Code:
Hibernate: insert into DOCUMENT (NUM_DOC, TYPE_DOC ,TYPE,HT, TTC) values (?, ?, ?, ?, ?)
Hibernate: insert into DOCUMENT_SALE (NUM_DOC, TYPE_DOC ,REF) values (?, ?, ?)
Hibernate: insert into DOCUMENT_SALE (NUM_DOC, TYPE_DOC ,) values (?, ?)
......
SEVERE: ORA-00001: violation single constraint
....
it insert twice in the table DOCUMENT_SALE.I do not understand where does the problem.
thank you in advance.