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