-->
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: bag using a combined key (and it's not the primary key)
PostPosted: Wed Jun 29, 2005 3:54 am 
Newbie

Joined: Wed Jun 29, 2005 3:25 am
Posts: 2
Hi

I have a mapping problem, that I need some help with.
Here is a very simple version of my problem.

My database looks like this:
Code:
   --------------       ---------------
   |     foo     |      |     bar     |
   --------------       ---------------
  *| int P       |     *| int P       |
  *| int U       |     *| int S       |
   | int S       |     *| int L       |
   --------------       ---------------
*=primarykey


So from foo you will get a list of bar if you use P and S as the key.

My two classes foo and bar looks like this:
Code:
public class foo{
  private Id id;
  private Integer s;
  private Collection barList;

  public static class Id implements Serializable {
    private Integer p;
    private Integer u;
    ...........
  }
  .........
}

public class bar{
  public static class Id implements Serializable {
    private Integer p;
    private Integer s;
    private Integer l;
    .........
  }
  .......
}


The mapping files look like this:
Code:
<hibernate-mapping schema="mavje">
  <class name="Foo" table="foo" lazy="true">
    <composite-id name="id" class="Foo$Id">
      <key-property name="p" column="P"/>
      <key-property name="u" column="U"/>
    </composite-id>
    <property name="s" column="S"/>
  </class>
</hibernate-mapping>

<hibernate-mapping schema="mavje">
  <class name="Bar" table="bar" lazy="true">
    <composite-id name="id" class="Bar$Id">
      <key-property name="p" column="P"/>
      <key-property name="s" column="S"/>
      <key-property name="l" column="L"/>
    </composite-id>
  </class>
</hibernate-mapping>


Now to the problem!!!
How do I map the barList in the class Foo?
It's straight forward if I was using the primary key from Foo to build the barList, but in my case I need a property from the combined primarykey and a normal property.

Any ideas???

Mads


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.