-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: problem in Inheritance mapping
PostPosted: Sat Oct 13, 2012 2:24 pm 
Newbie

Joined: Thu Oct 04, 2012 8:10 am
Posts: 4
Hi;
I have a problem mapping for this design;


Image

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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.