-->
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.  [ 2 posts ] 
Author Message
 Post subject: problem with getting extra field from join table
PostPosted: Tue Aug 01, 2006 10:46 am 
Newbie

Joined: Mon May 29, 2006 5:23 am
Posts: 7
Hello,

I have a problem with accessing a field of a join table. Underneath you'll find the table-structure:

-------
table PERSON(ID, NAME)
table PERSON_PROJECT(PERSON_ID, PROJECT_ID, extra_column)
table PROJECT (ID, NAME)

The tables PERSON and PROJECT have a many-to-many relationship with each other.
-------

In the PERSON mapping file and in the PROJECT mapping file i created a Set, so that my domain object Person has a Set of projects and the Project domain object has a Set of persons.

The mappings look like this:
----------------
<class name="test.Project">
<property name="name" column="name"/>
...etc
<set name="persons" table="PERSON_PROJECT">
<key column="PROJECT_ID"/>
<many-to-many name="person" column="PERSON_ID" class="test.Person"/>
</set>
</class>

<class name="test.Person">
<property name="name" column="name"/>
...etc
<set name="projects" table="PERSON_PROJECT">
<key column="PERSON_ID"/>
<many-to-many name="project" column="PROJECT_ID" class="test.Project"/>
</set>
</class>
-------------------


This works fine...but.., i cannot get the "extra_column" field from my join table. This is because the join table is not configured as a class with it's own mapping file.

Is there a decent way to get a property from a join table? Does it mean that I have to create another class?? Do i have to work with the "<composite element>" tag? (Problem here is that the hibernate reference has an example, but does not show the tables and the domain objects....)

Could anyone please help me by providing a good example to solve my problem?

Regards,
Martijn


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 7:02 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You do have to map the join table, at least as a composite-element, or you can map it as a class in its own right. There are many different ways to implement it, all reasonably obvious.

The exception would be when you have only one extra column, and it's a list index type: that is, it's some simple sequence based on one side of the relationship. Something like this:
  • objA1, objB1, 1
  • objA1, objB2, 2
  • objA2, objB3, 1
  • objA2, objB1, 2
In this case, you can implement it as a <list><many-to-many>, avoiding the need to map the join table.

_________________
Code tags are your friend. Know them and use them.


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