REOPEN: Version properties which are NULL in the database cause exceptions during a delete or update

Description

Reopening as a new defect since it appears that I cannot reopen it myself. was closed before I could even attach the test case. Please don't close this yet; let the test case speak for itself.

I tried using unsaved-value and it did not work. There are, in fact, bugs here.

Environment

None

Attachments

2

Activity

Show:

Fabio Maulo April 22, 2011 at 1:27 PM

In fact in your test you have:
// Unsure if there is a cross-platform way to do this.
// (Need to drop the "not null" constraint.)
ExecuteSql(session, "alter table Info alter column Version INT");

// ... and need to bypass NHibernate to insert the following rows, in order
// to simulate rows in a legacy database that were "already there".
ExecuteSql(session, "insert into Info values (1, 'Positive version')");
ExecuteSql(session, "insert into Info values (0, 'Zero version')");
ExecuteSql(session, "insert into Info values (null, 'NULL version')");
ExecuteSql(session, "insert into Info values (-1, 'Negative version')");

Fabio Maulo April 22, 2011 at 1:25 PM

That is because the version property shouldn't be null.
This is not a bug in NH you have only dirty values, not wrote using NH, in your DB.

Mike Pontillo April 22, 2011 at 1:20 PM

This is my tentative fix for the problem.

There are three issues:

(1) The IsOptional or IsNullable property needs to be set on the version Mapping.Property, or NHibernate will validate it incorrectly (at least, in my test case) because it thinks there should be a non-NULL constraint on the column. I am not sure what the correct fix is, but adding the line in RootClassBinder worked for me.

(2) Versioning always assumes a non-null version property.

(3) AbstractEntityPersister makes several assumptions that the version property is not null.

Won't Fix

Details

Assignee

Reporter

Components

Priority

Who's Looking?

Open Who's Looking?
Created April 22, 2011 at 1:13 PM
Updated April 22, 2011 at 1:27 PM
Resolved April 22, 2011 at 1:27 PM
Who's Looking?