-->
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.  [ 3 posts ] 
Author Message
 Post subject: Containment mapping with table-per-class.
PostPosted: Fri Dec 10, 2004 2:04 am 
Newbie

Joined: Fri Dec 10, 2004 1:52 am
Posts: 5
Hi,

How to map a normat containment using hibernate?

e.g.

I have a Teacher class that contains an array of Subjects he teaches.

public class Teacher {

private long TeacherID;
private String Name;
private Subject[] subjectsTaught;
}

And a Subject class

public class Subject implements Serializable {
private int SubjectId;
private String Name;
private int HrsperWeek;
private long TaughtBy;
}

I have 2 tables, with Subject Table having a foreign key to Teacher.

How to map this such that when I say session.save(teacherObject), I should get the subjects saved and their foreign keys set correctly?

If I just mark the 'subjectsTaught' member of Teacher as Property with type=Subject, and a many-to-one mapping for Subject's foreign key member 'TaughtBy', it throws an error,

multiple imports : Teacher.

One mroe, How can I get help on error messages displayed by hibernate, like meaning of 'multiple imports'


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 11, 2004 2:33 am 
Newbie

Joined: Fri Dec 10, 2004 1:52 am
Posts: 5
Hi again,

I could successfully do the mapping after using set instead of array for the 'many' side.

But, now I'm facing another problem.

When I call session.save(aNewTeacher) on the parent object, Hibernate correctly fires INSERT query. But it does not out the primary key of this inserted row in foreign key field of the child set of Subjects.

So I get Oracle error of cannot insert NULL into taughtby (foreign key field).

How should I overcome this?

Is there a forum for beginners also?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 11, 2004 4:46 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
The forum for beginners is called Hibernate Reference Documentation.

In your case look at chapter 16.

HTH
Ernst


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