Given this class mapped with JPA (using JPA 1.0 and Hibernate):
@Entity
public class Foo {
private int bar;
/* ... */
}
BAR
column set to NULL?bar
field when the corresponding column is NULL?Notes
I know this is not a best practice. The question is more out of curiosity and it is inspired by this situation:
NOT NULL
constraint is impractical. Bad data is expected, and the point of my code is to validate, clean up and/or reject data before loading it into the "real" database.boolean
flag which should default to false
.Java primitive types (such as int , double , or float ) cannot have null values, which you must consider in choosing your result expression and host expression types.
The JPA specification defines that during ordering, NULL values shall be handled in the same way as determined by the SQL standard. The standard specifies that all null values shall be returned before or after all non-null values. It's up to the database to pick one of the two options.
Null used as default Just as there is a default value for primitive types (e.g., 0 for integers, false for booleans), null is the default value for reference types.
I would rather use objects if a column may contain null value because Matheus's idea introduces false data. NULL <> 0
!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With