-->
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: <list-index column="??????"/>
PostPosted: Mon Mar 13, 2006 6:06 am 
Regular
Regular

Joined: Wed Mar 08, 2006 2:07 am
Posts: 50
Location: Bangalore
For an array tag we need to specify the list-index nested-tag (thats mandatory)
but my app doesnt need to maintain any particular sequence order.
The business tier has a class which has an array[] of a custom type.
But the database doesnt has any column for specifying the index.
So to create a mapping can I just create a column (dummy) and give its name in column attribute of list-index nested-tag and let the value inside
it be null (as the sequence doesnt matter to me).
Is that kind of thing possible ?


Quote:
array tag syntax :


Code:
<array name="speakers">
<list-index column="speaker_index"/>
<key column="event_id"/>
<one-to-many class="Speaker"/>
</array>



In the above example, if suppose i dont put any values in 'speaker_index' column (i.e. null values) what will be the effect ?


Top
 Profile  
 
 Post subject: You don't need to map it as an array then
PostPosted: Mon Mar 13, 2006 2:08 pm 
Beginner
Beginner

Joined: Mon Mar 14, 2005 6:07 pm
Posts: 36
If the order does not matter, then you are not mapping an array - it's a bag. The fact that it's an array in POJO shouldn't matter - simply convert a Collection to an array on the way in using the toArray method, and convert back to a collection on the way out, like this:
Code:
Speaker[] speakers;
...
void setSpeakers(Collection speakers ) {
    this.speakers = (Speaker[])speakers.toArray(new Speaker[speakers.size()]);
}
Collection getSpeakers() {
    return Arrays.asList(speakers);
}
...

I hope this helps.


Top
 Profile  
 
 Post subject: Re: You don't need to map it as an array then
PostPosted: Tue Mar 14, 2006 1:06 am 
Regular
Regular

Joined: Wed Mar 08, 2006 2:07 am
Posts: 50
Location: Bangalore
Yah, thats true. But the thing is that I am porting an existing Business app onto hibernate. So I cannot change existing interface in those class, I can only do whatever in xml and databases. So the API still remains like this :


Code:
Speaker[] speakers;
...
void setSpeakers(Speaker[] speakers ) {
    this.speakers = speakers;
}
Speaker[] getSpeakers() {
    return speakers;
}
...



To make the arrays in business tier classes to be populated by hibernate I can use only <array> tag ... but that requires a index column...So i am adding a new index column with null values as sequence doesnt matter to me.

PS - I will also use subselect inside <array> tag to conditionally populate elements in my array. (Just in case this info might be useful to you.)


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.