-->
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: Mapping to resolve column names as PKs in another table
PostPosted: Tue Apr 14, 2009 1:39 pm 
Newbie

Joined: Tue Apr 14, 2009 1:26 pm
Posts: 1
I'm designing a application for recording sports abilities for my friends to use.
Each User is measured in a range Moves grouped by Discipline.
Each Move has a Score associated with it.
There are a total of 67 Moves across 6 Disciplines.

I've got a Users table and Moves table.
Disciplines are groupings of Moves (each move exists in exactly one Discipline with no duplicates).
I'm not sure if at an Object level the Move should "know" what Discipline it belongs to?

I've got a Discipline table conatining Id and Name. Each Move entry then references a Discipline_Id.

I've another table called Assessment which is indexed by User_Id and each column represents a Move (Move_Id).
Each row in the Assessment table corresponds to one User.
So if the user is proficcent with a Move a value is set for that corresponding Move.
The actual Score of the Move is stored in the Move table so this can be changed if required.



The problem I'm having is tying the different things together. User is an entity with USER_ID, NAME, etc.
Assessments contains User_ID and T/F for each Move (USER_ID, MOVE_1, MOVE_2, MOVE_3, ... , MOVE_x) where x = ID of Move.
Moves are describes in the Moves table (MOVE_ID, NAME, SCORE, DISCIPLINE_ID)
Moves are groups by Disciplines (DISCIPLINE_ID, NAME)

I'm using a Service object to provide methods for recording a user's abilities and returning the assessments.
I've got mapping files created for everything except the ASSESSMENT table.

Code:
<hibernate-mapping>
    <class name="model.Move" table="MOVES">
    <id column="ID" name="id" type="long">
      <generator class="native"/>
    </id>
    <property column="NAME" name="name" type="string"/>
    <property column="ONE_HANDED_BONUS" name="onehandedbonus" type="boolean"/>
    <property column="OFFICIAL_SCORE" name="officialScore" type="int"/>
    <many-to-one column="DISCIPLINE_ID" name="discipline" not-null="true"/>
  </class>
</hibernate-mapping>

<hibernate-mapping>
      <class name="model.Discipline" table="DISCIPLINES">
    <id column="ID" name="id" type="long">
      <generator class="native"/>
    </id>
    <property column="NAME" name="name" type="string"/>
    <set name="moves" inverse="true">
            <key column="DISCIPLINE_ID"/>
            <one-to-many class="model.Move"/>
    </set>
  </class>
</hibernate-mapping>



Firstly I'm not sure how I should represent the ASSESSMENT as an object. I've got an ID, fair enough. The Moves, do I use a collection of Move objects or define each Move as a property?
Secondly I'll want to do things like resolve MOVE_2 to get the NAME and SCORE for a USER_ID from ASSESSMENT. But MOVE_2 is a column of ASSESSMENT.

e.g. For USER_ID = 123 I would get something like Contestant (USER_123.NAME) Peter scored (MOVE_2.SCORE) 6 for move (MOVE_2.NAME) Jump.

I want to be able to display an Assessment table containing a section for each Discipline.
Withing a Discipline section I list the Moves belong to that Discipline.
The Move Name followed by the Score and T/F if the User has completed the Move.
The total for each Discipline is provided.
The total for all Moves (Disciplines) is provided.

I'd like to define the ordering of the Moves within a Discipline when I present them (HTML table).
Once I can get the mappings setup I can figure out the operations.

I'm reading the on-line documentation but I'm not sure what the right solution is. I guess I don't know what the right answer is.

Thanks for any guidance.
Peter


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.