Hi Guys!Could anyone help me with my problem?
I have three tables, Contact, Industry and Contact_Industry. The Contact_Industry table just hold the association of the contact and industry.And I have just created two class (Contact and Industry based from here -->
http://forum.hibernate.org/old//717844.html )
Here's my class:
class Contact {
String name = null;
Set industry = null;
........
}
/* this is a tree structure table */
class Industry {
Set children = null;
Strng name = null;
.........
}
Here's my mapping
Industry.hbm.xml
<hibernate-mapping>
<class name="com.eon.cms.vo.Industry" table="industry">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<set name="children" inverse="true" lazy="false" cascade="save-update" order-by="industry_id_fk">
<key column="industry_id_fk"/>
<one-to-many class="com.eon.cms.vo.Industry"/>
</set>
<many-to-one name="parent" column="industry_id_fk" cascade="save-update" class="com.eon.cms.vo.Industry"/>
<property name="name" length="50"/>
</class>
</hibernate-mapping>
Contact.hbm.xml
<class name="com.eon.cms.vo.Contact" table="contact">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" length="200" />
<property name="telephoneNo" column="telephone_no" length="20" />
<property name="email" length="100"/>
<property name="address1" length="100"/>
<property name="address2" length="100"/>
<property name="remark" length="500"/>
<property name="createdDate" />
<property name="modifiedDate" />
<property name="modifiedBy" />
<property name="faxNo" column="fax_no" length="20" />
<property name="mobileNo" column="mobile_no" length="20" />
<property name="secretaryNo" column="secretary_no" length="20" />
<property name="referredBy" column="referred_by" length="200" />
<many-to-one name="sector" column="sector_id" not-null="true"/>
<set name="industry" table="contact_industry">
<key column="contact_id"/>
<composite-element class="com.eon.cms.vo.Contact">
<many-to-one name="industry" column="industry_id" class="com.eon.cms.vo.Industry" not-null="true"/>
</composite-element>
</set>
</class>
i first populated the Industry
try {
....
trans = session.beginTransaction();
Industry industry = new Industry("Media");
session.save(industry);
trans.commit();
} catch(Exception e) {
}
there's no problem the data was save but when i try to save the contact using the following,
try {
....
trans = session.beginTransaction();
Industry industry = (Industry)session.load(Industry.class,new Long(1));
Sector sector = (Sector)session.load(Sector.class,new Long(1));
contact contact = new Contact();
contact.setSector(sector);
Set industrySet = new HashSet();
industrySet.add(industry);
contact.setIndustry(industrySet);
session.save(contact);
trans.commit();
} catch(Exception e) {
}
the program runs fine and no error encountered but when i try to query the database, there's no contact save.
btw, im using postgres database.
Am i missing something here?
thanks
raymond