by Eabin 21 Mar 11:45
Bind error for null values

Hi Rob!

When ConcurrencyMode.ALL is used, and a bean has a loaded property with null value, UpdateMeta:bind() calls
all.dmlBind(bind, true, oldBean, false);

which will not bind the null value, and therefore fail with a "parameter #n not set" exception. even worse, all indexes are false too.

please fix :)

regards,
-erwin

22 Mar 05:42
by Rob

I am unable to reproduce, can you supply more information?

> which will not bind the null value, and therefore fail

Hmmm, null values are not bound in the where clause but are in the set clause... but I am unable to reproduce this issue (works fine for me) so I need more information to reproduce.

... for example: the notes field is null when fetched... so it appears in the update where as... and notes is null

update o_customer set name=?, notes=? where id=? and name=? and notes is null

Thanks, Rob.

22 Mar 20:03
by Eabin

i changed the db-layout (column not-nullable), so i cannot reproduce it anymore. when i find some time, maybe i can provide a simple test-case.

25 Mar 23:15
by Eabin

no test case yet, but i just stumbled over this again.

declared a new field:
private int xyz = 0;

the field is added in mysql:
alert table t add xyz int;
(which means the default value will be null).

after that, i cannot save the bean anymore. i need to do
update t set xyz=0 where xyz is null;
to be operational again. no lazy loading included.

26 Mar 00:25
by Rob

Hmmm, I'm not convinced this is a bug in Ebean (perhaps you are not suggesting it is).

In that... in using an primitive int rather than a Integer ... the assumption is that xyz can not be null.

Or said another way, if you want xyz to be nullable then you should use java.lang.Integer (and not a primitive int data type).

Does that sound reasonable?

26 Mar 01:47
by Rob

Just to add... that there is special treatment for primitive ID fields.

That is, if you use a primitive int/long for an ID field those value is 0 ... then Ebean treats that as "the ID has not been set" (similar to saying the ID field is null).

This is special treatment for ID fields only and doesn't apply to other fields.

26 Mar 14:06
by Eabin

i see, this sounds very reasonable.
Can Ebean detect if a db column is nullable, and issue some kind of warning if the field is a primitive type?

26 Mar 20:35
by Rob

Can Ebean detect if a db column is nullable, and issue some kind of warning if the field is a primitive type?

Yes, Ebean already detects if a db column is nullable... so yes, that is a very good idea (to log a warning).

I'll look into that.

Cheers, Rob.

28 Mar 09:47
by Rob

Logged as Enhancement 98

http://www.avaje.org/bugdetail-98.html

Create a New Topic

Title:
Body:
 
Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements
woResponse