1 Reply Latest reply on Oct 31, 2012 10:48 AM by Adam Warski

    problem in Inheritance mapping

    Dhifi Borni Newbie

      Hi;

      I have a problem mapping for this design;

      121013080525744537.png

      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:

      <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:

      <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:

      <hibernate-mapping>
         <subclass name="src.InvoiceSale" extends="src.DocumentSale"             
            discriminator-value="INVOICE_SALE">     
         </subclass>
      </hibernate-mapping>

       

      in code java

            InvoiceSale invoice = new InvoiceSale();
              //....
         Session session = service.getTheSession();
         session .saveOrUpdate(invoice );

       

      and this is what appears in the console

         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.