-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to implement nested arrays as columns?
PostPosted: Fri Jan 02, 2004 10:50 pm 
Newbie

Joined: Fri Jan 02, 2004 10:17 pm
Posts: 3
My problem is:
1. The top-level class A holds an array of N (hundreds) second-level classes B. I would like to have each class B in this array as a COLUMN in the table, which represents A. However, standard Hibernate options map array elements to ROWS.

2. Each class B in the above-mentioned array, in turn, holds a sub-array of M (again, hundreds) items - now, simple numbers, rather than entities. I would like to have this array, again, map to COLUMNS in a table, which represents B.

The endpoint I would like to have in the database is: when a top-level item A is added to the database, the following events take place:
- a new row in the 2-column or 3-column A-table is added;
- a new row in the N-column B-table is added;
- N new rows in the M-column C-table are added.

Tried to implement this using explicit declaration of N B-components in class A and M C-components in class B, but to no avail. I don't post the mappings because there are too many versions: with one-to-many, with composite-element, etc. If somebody cares to give me a hint, I would at least know what direction to pursue.
Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 03, 2004 7:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What you actually want can be done using 100 many-to-one in A, but it sucks a lot.
Why don't you adopt the traditional relational db usage (FK to a in B table)? And thus the hibernate way of one-to-many.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:08 pm 
Newbie

Joined: Fri Jan 02, 2004 10:17 pm
Posts: 3
Thank you, I have, finally, implemented it in more or less the way you've described:

Class A contains an array of classes B mapped as one-to-many
<array name="Bs" inverse="false" cascade="all">
<key column="A_ID"/>
<index column="B_NUM"/>
<one-to-many class="all.B"/>
</array>

Class B contains 128 instances of class C mapped as:

<class name="all.B" table="B" dynamic-update="false" dynamic-insert="false">
<id name="id" column="B_ID" type="int" unsaved-value="0">
<generator class="native"> </generator> </id>
<many-to-one
name="C1" <!-- And so on to C128 -->
class="all.C"
cascade="all"
outer-join="auto"
update="true"
insert="true"
column="S1" <!-- And so on to S128 -->
not-null="false"
unique="false" />
</class>

Class C contains 400 integer properties:
<class name="all.C" table="C" dynamic-update="false" dynamic-insert="false">
<id name="id" column="C_ID" type="int" unsaved-value="0" >
<generator class="native"> </generator> </id>
<property
name="s1" <!-- And so on to s400 -->
type="integer"
update="true"
insert="true"
column="S1" <!-- And so on to S400 -->
not-null="true"
/>
</class>


Presently, it works, but on
session.save(a);
I get an Out of memory exception. It does not appear if there are less B's in A (20 or so). There is a lot of available memory, though. We work with Postgres 7.4 Seems something should be done to cache settings - can't you tell what?

As you've mentioned, the whole idea seems to suck quite a bit, especially because most of time I don't need to load or save the whole of A, only several B's. CAN YOU SUGGEST A BETTER WAY?

Generally, the problem is common: mapping a multidimensional OLAP cube to relational structure. Maybe, there is some standard way to do this in Hibernate? Because this problem is quite general, I have posted it also to Application Architecture section.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 9:26 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Granted that I know zippo about what an OLAP cube is...

You have 128 many-to-one relationships. How about using many-to-many and programmatically restricting the number?

Or how about something like the ternary associations example from the manual (section6.10)

Code:
<map name="connections" lazy="true">
    <key column="node1_id"/>
    <index-many-to-many column="node2_id" class="Node"/>
    <many-to-many column="connection_id" class="Connection"/>
</map>


http://www.hibernate.org/hib_docs/reference/html/collections.html#collections-s1-11a


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