Columns in the Corda database schema should have correct NULL/NOT NULL constraints.

Description

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.

Assignee

Maksymilian Pawlak

Reporter

Chris Rankin

Labels

Priority

Medium

Fix versions

Ported to...

None

Feature Team

Corda Core

CVSS Vector

None

Engineering Teams

None

Severity

Medium
Configure