-->
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.  [ 2 posts ] 
Author Message
 Post subject: array initialization in Hibernate 3
PostPosted: Mon Nov 06, 2006 12:14 pm 
Newbie

Joined: Fri Nov 03, 2006 7:01 pm
Posts: 4
This was accidentially posted on NHibernate forum, but it should have been on Hibernate users form:

I have a question concerning how and where to initialize an array in Hibernate 3.

I will have an array of objects instead of java collection
interfaces. Somehow I got a very huge array, with the expected
not-null elements at the end of the array. All other elemtns are NULLs.

Here is the tables:

create table main_table (id number(9) not null, constraint main_pk
primary key (id));
create table sub_table (id number(9) not null, main_id number(9) not
null, constraint sub_pk primary key (id), constraint sub_fk foreign key
(main_id) references main_table (id));

I populated three rows of records on sub_table, with all main_id values
pointing to the primary key of the main_table.

here is the hibernate mapping file:
<array name="subs" cascade="all">
<key column="main_id" />
<list-index column="id" />
<one-to-many class="Sub" />
<array>

but when I called something.getSubs(), I got a very huge (over 2000) array,
only the last three elements were what I populated and expected.

I heard Hibernate array mapping is not as solid as collection interface
mapping. Is that because Hibernate array mapping unables to initialize a correct
length at run-time? Is there any work around on array mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 12:27 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
by any chance are the values in your index column starting at 1998? I'm not sure if it is the case with arrays, but with collections hibernate expects indexes to all start at 0. if there are numbers missing or inconsistencies those objects are replaced with nulls in memory.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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