views:

531

answers:

1

I am creating database Entities in my Java application and trying to rationalize between using an Integer or a Long as the class type of the "id" field. I am using Hibernate as my ORM which, in turn, will map this field to a column in the HSQLDB database.

My struggle is this: a Long is obviously larger and will handle a greater number of entries - but, at a very low level, I know that in the past (32bit systems) OS level reads would be 32bits wide. IE: a Long read would take two passes ... is that correct thinking?

If I use a Long today, would my HSQLDB queries run slower than had I used an Integer?

IE: would HSQLDB have to somehow use multiple read passes ... or use a larger internal structure ... or have too append two Integer size columns ... or something else obviously nonideal? Or, is it somehow a moot point with today's 64 bit processing - which, should handle a Long in one read (Long is 64 bits)?

+1  A: 

Use a Long. Even with an in-memory database, the performance impact is very likely not going to be significant relative to the rest of your application. It will however be an incredible hassle to go back and change the application later if you start to run out of identifiers.

cliff.meyers