Workaround for Null Default Values

View: New views
2 Messages — Rating Filter:   Alert me  

Workaround for Null Default Values

by tch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This has probably been asked before, but I couldn't find it. Is there
an easy way to make EclipseLink not include nulls in insert
statements? As is, it's including the null value, which is causing the
default value on in oracle to not be set.

I don't want to use the insertable=false attribute on the @Column
annotation, because sometimes I want to be able to specify the value.

Basically I want an attribute that's like, includeWhenNull=false ,
which when set would cause the column to be left out of the insert
query.

I thought nullable=false might take care of it, but it didn't.

Thanks,
Tim
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Workaround for Null Default Values

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

No way that I know of.  You can use a ReturningPolicy to omit an insert field and select it back, but nothing to omit it only if null.  Perhaps log an enhancement request.

In general it may be better to initialize the value in Java instead of the database.  Even if you omit the null, you still don't get the value back from the database, so your object becomes inconsistent with the database.

You might be able to hack something with a InsertObjectQuery Redirector on the DescriptorQueryManager, but that would be complicated.


Tim Hollosy wrote:
This has probably been asked before, but I couldn't find it. Is there
an easy way to make EclipseLink not include nulls in insert
statements? As is, it's including the null value, which is causing the
default value on in oracle to not be set.

I don't want to use the insertable=false attribute on the @Column
annotation, because sometimes I want to be able to specify the value.

Basically I want an attribute that's like, includeWhenNull=false ,
which when set would cause the column to be left out of the insert
query.

I thought nullable=false might take care of it, but it didn't.

Thanks,
Tim