Given this class mapped with JPA (using JPA 1.0 and Hibernate):
@Entity
public class Foo {
private int bar;
/* ... */
}
- What happens if I try to load a record which has the
BARcolumn set to NULL? - Can I specify how to set the
barfield 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:
- The database table is a staging table: adding a
NOT NULLconstraint 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. - I have acceptable default values for some fields. For example, a
booleanflag which should default tofalse.
2.
it solves your problem.