-->
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.  [ 3 posts ] 
Author Message
 Post subject: Association class mapping
PostPosted: Tue Jun 12, 2007 4:40 pm 
Newbie

Joined: Fri Oct 21, 2005 9:27 am
Posts: 13
Hi,

I've got a little problem with a mapping.

Ideally, I would have this :
Code:
public class Operator {
  // id, etc ...
  private List<Operator> destinations;
 
}

so it would be easy.

But of course I wouldn't ask my question here if it was that easy :)

The problem is that I need additional infos about these "destinations", like a status and a datetime.

So it would end up as two different classes :

Code:
public class Operator {
  //...
  List<Destination> destinations;
}

public class Destination {
  //...
  private Operator destinationOperator;
  private DestinationStatus status;
  private Date activeDate;
}

My problem is, how can I map this beast correctly ?
I've tried several solutions (Destination being either @Embedded or @Entity) but there are always flaws in the mapping.

I know I'm doing it wrong because it's not so uncommon, so it should exist a simple solution, no ?


Top
 Profile  
 
 Post subject: Re:
PostPosted: Tue Jun 12, 2007 5:03 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Try this :

In the mapping for Operator class:
Code:
<list name="destinations" inverse="true">
            <key column="operator_ID"/>
            <index column="list_index"/>
            <one-to-many class="Destination"/>
        </list>

In the mapping for the Destination class:
Code:
<many-to-one name="destinationOperator" class="Operator" column="operator_id"/>
<many-to-one name="status" class="DestinationStatus" column="status_id"/>
<property type="date" name="activeDate"/>

Regards,
Jitendra


Top
 Profile  
 
 Post subject: Re:
PostPosted: Fri Jun 15, 2007 5:11 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
If your problem is solved, please give appropriate credit.


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