What is the best type for storing IP-addresses in a database using Hibernate?
I though Byte[] or String, but is there a better way, or what do you use?
@Column(name = "range_from", nullable = false)
public Byte[] getRangeFrom() {
return rangeFrom;
}
public void setRangeFrom(Byte[] rangeFrom) {
this.rangeFrom = rangeFrom;
}
I store it in a long, very fast for lookup. You can use the following functions for conversion.
And this one
You may want to improve them by doing checks on the parameters.
It doesn't matter too much if you use Byte[] or String. Both will do the same job, it really just depends on your application and requirements.
I personally have always stored them as Strings.
I'm not aware of a better way to store them via Hibernate.
See https://forum.hibernate.org/viewtopic.php?f=1&t=996818&start=0
edit: Or you can use a long as in Pierre 303's example. In the end it really depends on your application and which type is the easiest to deal with for you.