-->
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.  [ 3 posts ] 
Author Message
 Post subject: <many-to-one and polymorphism
PostPosted: Tue Mar 28, 2006 9:46 pm 
Newbie

Joined: Tue Mar 28, 2006 9:31 pm
Posts: 13
Hello,

i decided to make use of the Table per subclass strategy and it works good for me.

I only have 1 problem: how can i map these classes to a property?
(the code below worked for "simple" mapped Object without inhetirance, after adding inhetirance, i get the error "Column 'paymentType_id' cannot be null" )

So my question is: how can i map the classes, as i far as i can see it should work this way.
Thank u very much, hard to explain this problem, hope the code below makes it clear.

Code:
<many-to-one name="paymentType" class="de.autotest24.bean.PaymentType" column="paymentType_id"/>
 


The mappingfile PaymentType.hbm.xml for the
Code:
<hibernate-mapping>

    <class name="de.autotest24.bean.PaymentType" table="paymenttype">
        <id name="paymentType_id" column="paymentType_id">
            <generator class="native"/>
        </id>
        <property name="description"/>
                 
        <joined-subclass name="de.autotest24.bean.CreditCardPaymentType" table="creditcardpaymenttype">
           <key column="paymentType_id"/>

           <property name="validUntil"/>
           <property name="creditCardNumber"/>
           <property name="creditCardOwnerName"/>
          </joined-subclass>
       <joined-subclass name="de.autotest24.bean.BankCollectionPaymentType" table="bankcollectionpaymenttype">
           <key column="paymentType_id"/>
              
           <property name="bankIdentifierCode"/>
           <property name="bankAccountNumber"/>
           <property name="bankAccountOwner"/>
       </joined-subclass>
    </class>

</hibernate-mapping>
       


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 11:01 pm 
Newbie

Joined: Tue Mar 28, 2006 9:31 pm
Posts: 13
Annotation : the code above is correct.

The real question is :
how can i tell i hibernate that he should insert the object referenced
by the name attribute - in this example de.autotest24.bean.PaymentType
instead of just referencing it, insert="true" dont did what i expected

Code:
<many-to-one lazy="false" name="paymentType" class="de.autotest24.bean.PaymentType" column="paymentType_id" insert="true"/>


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 11:52 pm 
Newbie

Joined: Tue Mar 28, 2006 9:31 pm
Posts: 13
Hello - its me again, i change my code to

Code:
db.writePaymentType(paymentType);
    db.writeMember(member);


works for me, well its a workaround, what i really want is that i give a member object to the database and all components of that object are written to database too


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

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.