Entity members should they be primitive data types or java data types?

前端 未结 3 879
死守一世寂寞
死守一世寂寞 2021-02-05 03:12

Is there a difference in declaring the enabled variable as Boolean or boolean? Which is preferable from a memory footprint perspective.

@Entity
class User {

            


        
3条回答
  •  甜味超标
    2021-02-05 03:57

    Kaleb's right - if any queries return a null value for "enabled" (in this case) then you have to use the object rather than the primitive.

    This is from the Hibernate FAQ:

    A PropertyAccessException often occurs when the object being passed to the setter method is of the wrong type. Check your type mappings for the offending property. (To see exactly which property was the problem, you might need to disable the CGLIB reflection optimizer.) However, the most common cause of this problem is that Hibernate attempted to assign null to a property of primitive type.

    If your object has a primitive-type property mapped to a nullable database column then you will need to use a Hibernate custom type to assign a sensible default (primitive) value for the case of a null column value. A better solution is usually to use a wrapper type for the Java property.

    https://www.hibernate.org/116.html

提交回复
热议问题