-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with session.save()???
PostPosted: Sun Feb 08, 2004 11:51 pm 
Beginner
Beginner

Joined: Fri Jan 23, 2004 5:08 am
Posts: 21
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2004 6:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You cannot use contact as a composite element since it's already an entity (check the reference guide).

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.