-->
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: Alternative Java model for One-To-Many relationship?
PostPosted: Thu Sep 29, 2011 5:19 pm 
Newbie

Joined: Thu Sep 29, 2011 5:15 pm
Posts: 2
Here's a simplified example of what I want to achieve:

I have 3 tables:

Code:
STUDENT {
   STUDENT_ID,
   NAME
}

HOBBY {
   STUDENT_REF,
   HOBBY
}

AWARD {
   STUDENT_REF,
   AWARDS
}


1. STUDENT_REF colums have a foreign key referring to STUDENT_ID column.
2. There is a One-To-Many relationship between STUDENT and HOBBY/AWARD.

The standard way to model this in Java classes is:

Code:
@Entity
class Student {
   int id;
   String name;

   @One-To-Many(...)
   Set<Hobby> hobbies;


   @One-To-Many(...)
   Set<Award> award;
}

@Entity
class Hobby {
  ...
}

@Entity
class Award {
  ...
}


However, I want to introduce another containing class - StudentDetails - which does not have a mapping to any table and model it thus:

Code:
@Entity
class Student {
   int id;
   String name;

   StudentDetails details;
}

class StudentDetails {
   @One-To-Many(...)
   Set<Hobby> hobbies;


   @One-To-Many(...)
   Set<Award> award;
}

@Entity
class Hobby {
  Student student;
  ...
}

@Entity
class Award {
   Student student;
  ...
}



Note that Hobby and Award classes have a reference back to Student and not to StudentDetails.

How can I achieve this? Should I be using embedded objects? I haven't (yet) figured out how. Any hints will be appreciated and devoured.

Thanks in advance
Praveen


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.