-->
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: how to add child X in (A is a B and B has X as child)
PostPosted: Mon Apr 17, 2006 12:53 am 
Newbie

Joined: Mon Jan 09, 2006 8:17 am
Posts: 19
hi,

Can someone kindly point me in the right direction. I am trying to add the address when creating the Buyer (TbBuyer) record. Buyer is inherited from User class (tbUser). But am not able to create the address record (TbAddress). Hibernate did not create the sql code to create it.
TB_BUYER and TB_USER records were created okay. But not, TB_ADDRESS record.

Please help. Much appreciated.

Hibernate version: 3.2

Mapping documents:

<class name="TbAddress" table="TB_ADDRESS">
<id name="id" type="short">
<column name="ID" />
<generator class="native" />
</id>
<many-to-one name="tbUser" class="TbUser" not-null="true">
<column name="FK_ADDRESS_USER_ID" not-null="true" />
</many-to-one>
</class>

<class name="TbUser" table="TB_USER">
<id name="id" type="short">
<column name="ID" />
<generator class="native" />
</id>
<property name="refContactAddrId" type="short">
<column name="REF_CONTACT_ADDR_ID" not-null="true" />
</property>
<property name="refUsercategoryId" type="short">
<column name="REF_USERCATEGORY_ID" not-null="true" />
</property>
<property name="firstnameC" type="string">
<column name="FIRSTNAME_C" length="50" />
</property>
<property name="middlenameC" type="string">
<column name="MIDDLENAME_C" length="50" />
</property>
<property name="lastnameC" type="string">
<column name="LASTNAME_C" length="50" />
</property>
<set name="tbAddresses" inverse="true">
<key>
<column name="FK_ADDRESS_USER_ID" not-null="true" />
</key>
<one-to-many class="TbAddress" />
</set>
<joined-subclass name="TbBuyer" table="TB_BUYER">
<key column="id"/>
<property name="buyerNameC" type="string">
<column name="BUYER_NAME_C" length="50" />
</property>
</joined-subclass>
</class>


Name and version of the database you are using: MySQL 4.1

Code:

public class TbUser  implements java.io.Serializable {
//public abstract class TbUser {
     private short id;
     private short refContactAddrId;
     private short refUsercategoryId;
     private String firstnameC;
     private String middlenameC;
     private String lastnameC;
     private Integer userCodeI;
     private Set<TbAddress> tbAddresses = new HashSet();
     ...
     ...

    public void setTbAddresses(Set<TbAddress> tbAddresses) {
        this.tbAddresses = tbAddresses;
    }
       
    // added this proc to try to add address but is not working
    public void addTbAddress(TbAddress tbAddress){
        tbAddress.setTbUser(this);
        tbAddresses.add(tbAddress);
    }
}

public class TbBuyer extends TbUser {
     private short id;
     private String buyerNameC;
     private BigDecimal buyerPremiumR;
     .... 
     ....
    public void setBuyerNameC(String buyerNameC) {
        this.buyerNameC = buyerNameC;
    }
}
       
=============  code sniplets ==================

        TbBuyer tbBuyer = new TbBuyer();
        TbAddress tbAddress = new TbAddress();
        HibernateUtils hibernateUtils = new HibernateUtils();
       
        tbBuyer.setBuyerNameC("BuyerID");       
        tbBuyer.setFirstnameC("JOE");
       
        tbAddress.setStreetC("2 View Heights");
        // how to add address when the access is via TbUser class
        tbBuyer.addTbAddress(tbAddress);     
        hibernateUtils.saveOrUpdate(tbBuyer);



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.