-->
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.  [ 5 posts ] 
Author Message
 Post subject: Association table
PostPosted: Sat Dec 27, 2003 10:36 pm 
Beginner
Beginner

Joined: Sun Dec 21, 2003 11:19 pm
Posts: 22
Location: Kentucky, USA
Problem domain: A Course has multiple Sections with Students.

OO Model: Students is a m:m with Section that requires an Association class (SectionStudent) that has additional value attributes like beg / end dates and calculated attributes like points earned / points possible.

Database Model (hsql):
Code:
CREATE TABLE PERSON(PERSONID BIGINT NOT NULL IDENTITY PRIMARY KEY,SUBCLASS VARCHAR(255) NOT NULL,UPDATECOUNT INTEGER NOT NULL,FNAME VARCHAR(25),PNAME VARCHAR(25),COMMENT VARCHAR(50),MNAME VARCHAR(25),LNAME VARCHAR(25),GENDER CHAR(1),SUFFIX VARCHAR(10),STUDNUM VARCHAR(25),STATUS SHORT)

CREATE TABLE SECTION(SECTIONID BIGINT NOT NULL IDENTITY PRIMARY KEY,UPDATECOUNT INTEGER NOT NULL,DESCRIPTION VARCHAR(50),PERIOD VARCHAR(50),MEETS VARCHAR(50),COMMENT VARCHAR(50),COURSE_UID BIGINT NOT NULL, ORDER INTEGER)

CREATE TABLE SECTION_STUDENT(SECTION_UID BIGINT NOT NULL,PERSON_UID BIGINT NOT NULL,BEGDATE DATE,ENDDATE DATE,CONSTRAINT SYS_PK_SECTION_STUDENT PRIMARY KEY(PERSON_UID,SECTION_UID),CONSTRAINT FK2D6F2E1224877F6 FOREIGN KEY(SECTION_UID) REFERENCES SECTION(SECTIONID),CONSTRAINT FK2D6F2E12878DC66 FOREIGN KEY(PERSON_UID) REFERENCES PERSON(PERSONID))

Question:
I am using Middlegen as a starting point for the mapping files and expect to generate the mapping files using Xdoclet tags in the .java files. When Middlegen creates the mapping for SectionStudent, it creates a composite id for SectionId, PersonId which makes sense. It also creates a new class SectionStudentPK to represent that value. Is this strictly necessary? It seems to me that the class is overhead that could be eliminated with a little extra code on the association class SectionStudent. But I am very new to Hibernate and want to make sure I am not missing a subtle (or obvious) reason for the additional class.

I appreciate your time and input!
Timothy Vogel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 29, 2003 5:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The PK class is not required if you map your relation like the example in the 7.2 section of the reference guide.

If you map your association with an entity (see the doc for definition), then having a PK class is a good design, but not strictly needed.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2004 12:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The recommended approach is to use external classes for compound keys but you do not have to. Middlegen has ant attribute option to generate the compound keys integrated with the POJO rather than produce the separate class. See the Middlegen doco http://hibernate.bluemars.net/98.html.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2004 12:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Just in case you did not see it add

Code:
     genIntergratedCompositeKeys="true"


to your Ant - Middlegen hibernate plugin tag.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2004 9:01 am 
Beginner
Beginner

Joined: Sun Dec 21, 2003 11:19 pm
Posts: 22
Location: Kentucky, USA
David,
Thanks for the pointers!


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