-->
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: Both a <map> and a <one-to-one>?
PostPosted: Fri Oct 24, 2008 12:15 pm 
Newbie

Joined: Tue Sep 16, 2008 3:52 pm
Posts: 4
Location: Austin
Here's the situation: I have an entity class A. Inside it, it has a Map<Number, B> where B is another entity class. The number is stored as a property of B. B also stores a reference back to A.

So the tables look like:
Code:
A:
  aID NUMBER(19, 0),
  primary key(aID)

B:
  bID NUMBER(19, 0),
  aID NUMBER(19, 0),
  mapKey NUMBER,
  primary key(bID)
  foreign key(aID references A)


In the Java code, I've got:
Code:
class A {
  private Long aID;
  private Map<Number, B> bMap; //Pretend I've got get/set methods
  private B bDefault;
  public B findB(Number mapKey) {
    if (mapKey == null) {
      return bDefault;
    } else {
      return getBMap().get(mapKey);
    }
  }
}

class B {
  private Long bID;
  private A parent;
  private Number mapKey;
}


The problem is the bDefault property of A. The idea is that bDefault is the instance of B that I want to find when the mapKey Number is null. Obviously, I can't put it into the map because the key is null. So how do I map it in hibernate to get it to load & save properly? I can't use <one-to-one> because there's more than one entry in table B with the same aID. Is there a workaround that doesn't involve me making up a goofy number to substitute for null?

Thanks for your help,
Dan
[/code]


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.