This is not really related to Hibernate or how you represent things in the database, but is an example of a difference that matter when it comes to using primitive versus wrapper types.
Today a colleague of mine had a problem with removing items from a List. In principle the code was as simple as below, except that variable declaration was a bit more spread out so it was not immediately visible that
index was an Integer.
Code:
Integer index = ...
List aList = ....
aList.remove(index)
The problem was that nothing was removed from the list. The list had some elements and no matter what the index was nothing happened. Didn't even get ArrayIndexOutOfBoundsException:s when trying index values outside the size of the list...
Hmmm.... turned out that List.remove() comes in two variants:
Code:
List.remove(int)
List.remove(Object)
where the first removes an object by index and the latter removes the specified object. The code above calls the
List.remove(Object) method and since the the list contained String objects and not Integer objects nothing was removed.
So the bottom line is that auto-boxing of wrapper classes is not always your friend. Consider, for example, the case when an API evolves. In the first version there is only Foo.remove(int) and your code works fine because of auto-boxing. In the second version the Foo.remove(Objects) method is added. If you recompile your code against the new API it calls the new remove(Object) method which may cause problems.