Statement 1: You should always use primitive types for your entity instead of their wrapper-types. Primitiv types are more performant.
Statement 2: You should always use wrapper types for your entity instead of their primitive-types, because Wrapper-Types can have NULL-Value which can be the representation of a NULL-Value of a column in a database. Hence: Use Wrapper-Types in Entity-Beans.
Do you have a performance problem when accessing the field? If so, you need to optimize. ("Premature optimisation is the root of all evil.") But expressing "special" values like "not initalised" or "infinity" with values like -1 or 9999 will lead to problems.
If not, follow the business. The field can be null? Can't be achieved with primitives, so don't use them then. Typical for primary keys.
Joined: Jun 28, 2008
Do you have a performance problem when accessing the field
No not really
"Premature optimisation is the root of all evil."
Yes, indeed its true.
I am convinced now - I use Wrapper-Types. I saw in such tutorials that they use primitives and could not find a reasonable reason.
I always use primitives for non-nullable fields and wrapper objects for nullable fields. If you use a primitive on a nullable field JPA (Hibernate in JBoss) will throw an error when it reads a null value from the database and attempts to put that value into a primitive field.
subject: Do not use primitive types in JPA for mapping