Ok, I think I'm handling this right, but I'm still so new to Hibernate that I wanted to run this by anyone with a bit more experience to make sure I'm not off base.
I have two entities in my system, a
CBTCourse and a
User. Theses two entities have a many-to-many relationship. That relationship is actually defined in its own class,
AssignedCourse because the relationship itself has some properties. For instance, a couple of those properties are targetCompleteionDate, assignedDate, and proficiencyLevel.
So at this point in my system, there are the three entities,
CBTCourse,
User, and
AssignedCourse. Because the relationship between
CBTCourse and
User is a many-to-many one, my first instinct was to place the following in the
User mapping file:
Code:
<set
name="courses"
lazy="true"
inverse="false">
<key column="user_id" />
<many-to-many
class="com.cadtrain.coachlms.common.dataobject.CBTCourseDO"
column="course_id"
outer-join="auto" />
</set>
However, I couldn't figure out how to continue down this path and capture the properties that I knew were represented by the
AssignedCourse class.
So now, I'm approaching this differently and it's this alternative approach that I wanted to run past some folks with a bit more experience with Hibernate than myself. I'm relating the
User to the
AssignedCourse with a one-to-many mapping and then relating the
AssignedCourse to the
CBTCourse with a many-to-one mapping.
Does this make sense? It appears to do so, from my perspective, but for some reason, I feel like I'm violating some kind of sacred rule somewhere along the way. :)
One of the by-products of this approach was that the associative entity, the
AsignedCourse is actually using a surrogate key instead of a composite key made up of the course_id and the user_id. Again, this feels quiet odd from the perspective the the database relational model, but from reading the Hibernate refernce manual, there appeard to be quite a few pitfalls associated with composite keys that I really didn't want to mess with.
-Matt