-->
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 map Set<Long> efficiently?
PostPosted: Thu Aug 09, 2007 3:25 am 
Newbie

Joined: Sun Mar 12, 2006 2:44 pm
Posts: 10
Hi,

I have to keep a large number of long numbers associated with specified type of object (some my class has to have a references to those numbers). It's about a few thousands per object. In code it would be keep as Set<Long> (but that could be changed).

My idea was to make a long wrapper (MyLong):

Code:
class MyLong {
  private long value;
...
}


and later:
Code:
class Keeper {
  private Set<MyLong> longs;
...
}


but maybe a set/array of longs could be mapped directly using Hibernate or it can be done more efficiently?


Thanks for help
Marcin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 4:03 am 
Newbie

Joined: Sat Oct 28, 2006 6:16 am
Posts: 17
You can use the element tag to map a collection of longs (so you can map Set<Long> instead of Set<MyLong>). See http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#collections-ofvalues.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 4:27 am 
Newbie

Joined: Sat Oct 28, 2006 6:16 am
Posts: 17
For more efficiency you could also try mapping a blob to an array of bytes and then convert this to and from an array of longs in java code. To map an array of bytes to a blob see binary at http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#mapping-types-basictypes and at http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#mapping-declaration-property. To convert to and from the byte array the second solution at http://java.ittoolbox.com/groups/technical-functional/java-l/long-to-byte-array-1229531# looks good in terms of lines of code but I'll leave that up to you. Good Luck!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 9:54 am 
Newbie

Joined: Sun Mar 12, 2006 2:44 pm
Posts: 10
Thanks, mapping with "element" tag works fine for Set<Long>.
In the next iteration I will try to optimize it following your suggestions.


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.