-->
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: bidirectional one-to-many mappingwith interface involved
PostPosted: Tue Mar 16, 2004 12:07 pm 
Beginner
Beginner

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 20
Hi,

I'm wondering how to map the class hierarchy below, given the condition that classes A1 and A2 need to have independant Id colums (table-per-concret class as I understood).

Code:
interface A {}

class A1 implements A{
  private Map collectionC;
}

class A2 implements A{
  private Map collectionC;
}

class C {
  private A parent;
}


I tried this mapping, but it requires a mapping exists for interface A - this (as my understanding) will force me into the table-per-subclass scenario.

Could anyone advise on how can I map the relationship with table-per-concret class method?

Code:
<class name="A1">
  ...
  <map name="collectionC" inverse="true">
    <key column="parentId"/>
    <index column="keyC">
    <one-to-many class="C">
  </map>
</class>

<class name="A2">
  ...
  <map name="collectionC" inverse="true">
    <key column="parentId"/>
    <index column="keyC">
    <one-to-many class="C">
  </map>
</class>

<class name="C">
  ...
  <many-to-one class="A" column="parentId">
</class>


regards,
Dan


Top
 Profile  
 
 Post subject: one-to-many collection: java.util.Map and <any>
PostPosted: Tue Mar 16, 2004 4:24 pm 
Beginner
Beginner

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 20
I also tried this:
Code:
<any name="parent" meta-type="class" id-type="long">
  <column name="PARENT_CLASS" />
  <column name="PARENT_ID" />
</any>


But this seems not working with the <map> collection of class A1 and A2. Basically, the mapping will generate a table for class C like this:

<column unid>
<column parent_class>
<column parent_id>
<column parentid>

The last column is created because there is a <key column="parentId"> line in the <map> statements for classes A1 and A2.

When I call C.setParent(A1) and persist the objects, the "parentId" column is empty because it is not in the "many-to-any" mapping.

If I change the key to <key column="parent_Id"/> (which is same as the "any" declaration), I will get "duplicate column name" error.

So, can I use java.util.Map for one-to-many collections after all if there is an "any" on the "many" end?

Dan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 12:35 pm 
Beginner
Beginner

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 20
Well, it turned out to be a problem to cases: if I change the collection mapping's key column (parent_id) to exactly the same (PARENT_ID) as in the <any> mapping, everything works fine now.
Just curious about one thing:
<any> doesn't currently support "lazy" attribute. Is it possible to add this support after all? Or is there a way around?

It would be more efficient in the following scenario:
Code:
class A1 implements A{
  private Collection collectionOfB;
}
Class A2 implements A{
  private Collection collectionOfB;
}
class B {
  private A parent;
}

I use a one-to-many for A1 and A2 to associate B collection. And use "any" to map the many-to-one from B to A1 or A2 (which is the simplest way came out of my mind).

When I load B using a query like "from B where B.timeStamp>:today", I don't necessarily always want to load A, or call B.getParent().


Regards,
Dan


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.