-->
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.  [ 15 posts ] 
Author Message
 Post subject: Mapping hundreds of int columns
PostPosted: Sat Mar 25, 2006 9:18 am 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
I have about 300 columns named "Item1", "Item2", ... etc. I want to map these to an int[] array on my class where each column maps to one value in the array.

Is this possible?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 9:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use a usertype

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 9:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
and fire your DBA :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 10:35 am 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
No, a user type does not work.

A user type still requires mapping one column to one value. What would I put in the .hbm.xml file?

<property name="Items" column="xxx" type="test.ArrayColumns, test" />

What would I put in place of the xxx?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 10:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
<property name="myarray">
<column name="item1"/>
...
<column name="itemn"/>
</property>

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 10:47 am 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
Thanks, but what I am trying to avoid is listing all column names, since there are so many. Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 5:59 pm 
Beginner
Beginner

Joined: Mon Nov 21, 2005 6:38 pm
Posts: 30
Location: New Zealand
You could try using MyGeneration to generate your mappings from the DB Schema.

But if your schema is static, then it's only 10 mins out of your life to cut/paste
<column name="item1"/> etc (per Emmanuel's post) and create the mappings.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 4:52 pm 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
The DBA in me says that you should (if possible) normalize your
table structure to avoid having 300+ int columns...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 11:35 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
I dont see how normalization would help in this case. I have columns named Item1, Item2, ... Item255. Why would I split these into multiple tables? That just slows it down because now I have needless joins.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 12:46 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
It would help by getting rid of the original problem - hundreds of int columns in one table. Which is the lesser of two evils - you decide. Given that the columns have an identical base name "Item" and only vary by a number at the end (kinda like a primary key), it seems like a one-to-many or many-to-many relationship would make more sense. Most database systems do relationships very well, hence the term "relational" in RDBMS. Is there a business domain reason against using relationships other than the perceived slowness?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 8:15 am 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
You might be right but its too late to change that now.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 8:57 pm 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
Have you looked at using a <dynamic-component> mapping? That will map it to an IDictionary rather than an array, but isn't that better than defining 100 properties on your class?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 11:03 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
I tried searching for google on that and I only found some source code and some very obscure and complex references to it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 11:22 pm 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
Yes I've never tried using it before and my interpretation of the documentation could certainly be wrong. I guess you'll need to just give it a try and see what happens.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 05, 2006 4:03 pm 
Newbie

Joined: Wed Apr 05, 2006 3:53 pm
Posts: 1
k-dub wrote:
It would help by getting rid of the original problem - hundreds of int columns in one table. Which is the lesser of two evils - you decide. Given that the columns have an identical base name "Item" and only vary by a number at the end (kinda like a primary key), it seems like a one-to-many or many-to-many relationship would make more sense. Most database systems do relationships very well, hence the term "relational" in RDBMS. Is there a business domain reason against using relationships other than the perceived slowness?


You are absolutely right from a design standpoint, but unfortunately there's such thing as performance. A classical one-to-many solution results in multiple joins. As a result the performance degrade significantly.

I've been having the same problem and had to redesign my data model to use the same "Item1", "Item2"... layout to avoid those joins. At the moment I believe I reached a compromise by using one-to-many between the "master" record and "item pools" - records, containing 10 columns (Item1, Item2,...) each. This way it is more flexible, and I am not limited by say 100 columns.

Now, the hibernate aspect. For one, you can use <dynamic-component>. For me it didn't work as I'm using Hibernate annotations, which do not support it yet. So I ended up with creating a composite user type, which allows you to map your attribute to multiple columns. Works pretty well, and there's no significant drop in performance.


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