-->
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: Many-to-many relation, intermediate column
PostPosted: Wed Mar 23, 2011 12:54 pm 
Newbie

Joined: Wed Mar 23, 2011 12:46 pm
Posts: 2
I've been bumping my head on this problem and hope to find a solution here.

I have a "many-to-many" relation (Users -> UserState -> State)
A user can have many non-unique states which can change over time, defined in my intermediate table. (UserState)

I'm uncertain how I could gain acces to UserState.StateDate, which holds the moment the record was created.
Is there a way to map the column from the intermediate table to my State object or what would the most pragmatic way to gain access to the dates ?

Take a look at the bag

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="datatransfer" namespace="datatransfer">
  <class name="datatransfer.User,datatransfer" table="Users">
    <!-- Unsaved-value = insert vs. update id -->
    <id name="ID" column="ID" type="int" unsaved-value="0">
      <!-- What will generate new id's ?-->
      <generator class="native"></generator>
    </id>
    <property name="Name" column="Name" type="string" length="50" not-null="false" />
    <property name="FirstName" column="FirstName" type="string" length="50" not-null="false" />
    <property name="Email" column="Email" type="string" length="50" not-null="false" />
    <property name="Created" column="Created" type="DateTime" not-null="false" />

    <bag name="States" table="UserState" lazy="false">
      <key column="UserID" />
      <many-to-many class="datatransfer.State,datatransfer" column="ID" fetch="join">
        <column name="ID" />
      </many-to-many>
    </bag>
  </class>
</hibernate-mapping>


Thanks for any pointers...


Top
 Profile  
 
 Post subject: Re: Many-to-many relation, intermediate column
PostPosted: Thu Mar 24, 2011 9:32 am 
Newbie

Joined: Wed Mar 23, 2011 12:46 pm
Posts: 2
As I couldn't find a way to inject the property or do something creative, I came to the following solution:

Creating an intermediate class UserState linked with one-to-many relations.
It's less elegant to do "User.States[x].StateDetail" as to User.States[x], but it works.


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.