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.

Activity

Show:
Michele Sollecito
April 4, 2018, 10:06 AM

as discussed, moving it for GA and assigning to D&D team.

Gavin Thomas
April 4, 2018, 4:40 PM

Fix for required for DP3 but expected to be fixed when database migration scripts R3 provide sort out the column constraints

Szymon Sztuka
May 29, 2018, 2:33 PM
Edited

did the change, I carried on with PersistentStateRef API change. Done.

Szymon Sztuka
June 8, 2018, 2:59 PM

Set to In Progress - found some problems with Liquibase integration.

Katelyn Baker
September 10, 2018, 9:56 AM

This was already backported to V3 in June https://github.com/corda/corda/pull/3303 so not sure why it was marked as failing CP

Assignee

Maksymilian Pawlak

Reporter

Chris Rankin

Labels

Sprint

None

Epic Link

None

Priority

Medium

Severity

Medium

CVSS Score

None

CVSS Vector

None

Due Date

None

Engineering Teams

None

Fix versions

Affects versions

None

Ported to...

None

Story Points / Dev Days

None
Configure