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);