can it be considered a best practice to use Integer to map all database integers that are explicitly 8bit or 16bit (MySQL TINYINT and SMALLINT)? I started by using java.lang.Byte and java.lang.Short, but then realized writing new Short((short)12345) was anything near what I consider clean code. Also, the MySQL JDBC driver returns Integer for these two types. It's definitely not a coincidence...
If the column is explicitly 8-bit specifically because it models a number which can be between -256 and +255, then you might want to have something in your application which enforces that. Using Byte might help, but even then an arithmetic operation which overflows the byte will silently wrap around, yielding the wrong data.
On the other hand if you used that column type to model a single-digit field and you mostly chose that type to save disk space, then maybe you can just use an Integer internally in your code.
It all depends on how tightly you want to control the mapping between the program data and the database data. Even so it might be simpler to just use Integer for the fields and control the range limits in your code, since using Short or Byte doesn't help with that at all.
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads