-->
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: advice: doing a one-to-many create
PostPosted: Mon Oct 25, 2004 6:27 am 
Newbie

Joined: Thu Oct 14, 2004 11:07 pm
Posts: 1
Hibernate version:2.1.6

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:Oracle 9i

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


I have 2 tables , one is the parent with a string primary key and the other is child with a composite primary key. The child's composite key contains a referenced foreign key which is the primary key of the parent. the two mapping files are like this :

Parent Primary Key
<id
name="testId"
type="java.lang.String"
column="TEST_ID"
length="20"
>
<generator class="assigned" />
</id>

Child Composite Key
<composite-id name="comp_id" class="child">
<key-property
name="createDt"
column="CREATE_DT"
type="java.sql.Timestamp"
length="7"
/>
<!-- bi-directional many-to-one association to Parent-->
<key-many-to-one
name="testId"
class="Parent"

>
<column name="TEST_ID" />
</key-many-to-one>
</composite-id>

I created a parent class and a child class, set all the values for both classes. And tried to do the following:
HashSet hs = new HashSet();
Parent parent = new Parent();
parent.setTestId("test");
Child child = new Child();
child.setCompId("child",parent);
hs.add(child);
parent.setChild(hs);

Session ses = SessionFactory.openSession();
Transaction tx = ses.beginTransaction();
session.save(parent);
tx.commit();

From the code above I'm trying to create a parent record and a child record at one time by storing the created Child class into a hashset which in turn stores into the set method inside the parent class. But however only the parent record is created and the child record is not created. I got the message from the log file Collection found: [Child#330], was: [<unreferenced>]; but i do not know what it means. But however i can get round by the following codes;

session.save(parent);
session.save(child);

But I want to know is there anyway for me just to do a save on parent class (with the child class stored inside the class) rather than to do 2 save methods.

Would appreciate if anyone could help. Feel free to comment if what i did is wrong.


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.