The Hibernate @Column annotation has the following default values:
nullable = true
insertable = true
updateable = true
So Hibernate expects to be able to insert NULL values into the database by default. However, Corda's Kotlin entity classes do not always set nullable=false on their columns, even when the Kotlin type explicitly disallows null values. E.g. the VaultStates entity:
This entity seems to expect @Colum(nullable=false) by default as it never sets this flag when it needs to and only sets it when it doesn't.
Similarly, AbstractCashSelection.attemptSpend() is clearly (and incorrectly) assuming that it can never read NULL values from the database:
because getLong() and getInt() both return Java primitive types that are zero for NULL values. Developers are expected to call wasNull() to discover if the column was NULL or not.
Our Hibernate entities need to impose the correct NULL/NOT NULL constraints on the database - whatever these correct values actually are.
as discussed, moving it for GA and assigning to D&D team.
Fix for required for DP3 but expected to be fixed when database migration scripts R3 provide sort out the column constraints
did the change, I carried on with PersistentStateRef API change. Done.
Set to In Progress - found some problems with Liquibase integration.