NN constraint

Posts   
 
    
orenpeled
User
Posts: 53
Joined: 25-Jul-2005
# Posted on: 23-Mar-2006 10:35:47   

Hi,

I tried to insert a new record with some NULL values, and I got an exception since those fields are NN. So I altered the table by setting the problematic fields to be nullable, WITHOUT regenerating the classes. I used the old entity-class to perform the insertion, and it succeeded.

This brought me to conclude that the adapter does not consult the persistence-info for this NULL issue before performing the query in th DB, and I wonder - why? Wouldn't it be more efficient to consult (maybe not by default since it can be dangerous, however letting the developer to decide seems like a good solution to me)?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 23-Mar-2006 14:34:14   

It does check if you explicitly set a field to NULL: check EntityBase2.ValidateValue. There validation result will be false if the value is null and the field isn't nullable. A validation result of false will never result in a field to be set to the value.

Though there's another thing: a field in a new entity which isn't set to a value. That also results in a NULL in the insert. This isn't checked. It also doesn't matter if it would be checked: either way you'll get an exception.

Frans Bouma | Lead developer LLBLGen Pro