-->
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.  [ 6 posts ] 
Author Message
 Post subject: Best way to store ip address?
PostPosted: Thu May 14, 2009 1:36 am 
Beginner
Beginner

Joined: Sat Feb 07, 2009 4:08 pm
Posts: 22
Location: New York City
I was wondering what is the hibernate preferred way to deal with an ip address field?


Top
 Profile  
 
 Post subject: Re: Best way to store ip address?
PostPosted: Thu May 14, 2009 4:31 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi, I would store the result of
Code:
byte[]    getAddress()
or
Code:
String    getHostAddress()
from java.net.InetAddress.

Greetings Michael


Top
 Profile  
 
 Post subject: Re: Best way to store ip address?
PostPosted: Thu May 14, 2009 5:01 am 
Beginner
Beginner

Joined: Sat Feb 07, 2009 4:08 pm
Posts: 22
Location: New York City
Thanks for you comments. What data type would you use in your Entity?

I guess what I was really getting at was: considering this functionality available in MySQL:
Code:
The INET_ATON() function converts Internet addresses from the numbers-and-dots notation into a 32-bit unsigned integer, and INET_NTOA() does the opposite


I was wondering if there was any best practices way to handle that same concept using hibernate - so that as far as indexing ip addresses was concerned you could deal with an integer...


Top
 Profile  
 
 Post subject: Re: Best way to store ip address?
PostPosted: Thu May 14, 2009 5:24 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
I don't know about any mapping type for an IP address in Hibernate, but you can still create a custom mapping type. It's really easy.

Have a look into the documentation: http://docs.jboss.org/hibernate/stable/ ... pes-custom


Top
 Profile  
 
 Post subject: Re: Best way to store ip address?
PostPosted: Thu May 14, 2009 7:54 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
JohnRock wrote:
Thanks for you comments. What data type would you use in your Entity?

As mentioned above byte[] or String, you can provide special getter ans setter to wrap them in and off the InetAddress. What to prefer depends on your requirements.

Quote:
I guess what I was really getting at was: considering this functionality available in MySQL:
Code:
The INET_ATON() function converts Internet addresses from the numbers-and-dots notation into a 32-bit unsigned integer, and INET_NTOA() does the opposite



Don't rely on any db functions, cause you will loose the strength of hibernate, that it is db independent.

Quote:
I was wondering if there was any best practices way to handle that same concept using hibernate - so that as far as indexing ip addresses was concerned you could deal with an integer...


byte[] should be usable as index, if performance isn't well you can compute an hashcode for it.
Also most db's support strings as index.

Mapping to an int or long ist not suitable, if you want to support IPV4 and IPV6 (both are to short for version 6).

Cause java don't supports unsigned ints, i wouldn't use it, even when supporting only IPV4 would be enough. Also it would be a quite dirty solution, even it has some advantages in pefomance.

But don't worry so much about performance, there will be much bigger performance drawbacks, you will have to worry in the future. Otherwise you will have to abandond hibernate and rely on stored procedurce, if performance is so crucial.

Greetings Michael


Top
 Profile  
 
 Post subject: Re: Best way to store ip address?
PostPosted: Thu May 14, 2009 2:03 pm 
Beginner
Beginner

Joined: Sat Feb 07, 2009 4:08 pm
Posts: 22
Location: New York City
Thanks for your insights. Very helpful.

John


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