Set values to null?

30 views
Skip to first unread message

Nando

unread,
Mar 8, 2010, 4:28:38 PM3/8/10
to cf-orm-dev
Is there a way to set values to null using CF Hibernate like you can
with a cfqueryparam? eg:

cfqueryparam
value="#arguments.getEndTime()#"
cfsqltype="cf_sql_datetime" null="#NOT
isDate(arguments.getEndTime())#"

I don't find anything in the docs.

Thanks,

Nando

Dorioo

unread,
Mar 8, 2010, 4:38:34 PM3/8/10
to cf-or...@googlegroups.com
Maybe you can do the check beforehand. Something like

if NOT isDate(arguments.getEndTime())
obj.setDate(javaCast("null",0))
else
obj.setDate(arguments.getEndTime())

- Gabriel

> --
> You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
> To post to this group, send email to cf-or...@googlegroups.com.
> To unsubscribe from this group, send email to cf-orm-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cf-orm-dev?hl=en.
>
>

Henry Ho

unread,
Mar 8, 2010, 4:39:20 PM3/8/10
to cf-orm-dev
Either write a method (e.g. removeEndDate() ) that calls
StructDelete(variables, "endDate");

Or setEndDate(JavaCast("null", ""));


Henry

Nando

unread,
Mar 8, 2010, 4:45:38 PM3/8/10
to cf-orm-dev
Ok, and then if I call entitySave(obj), endDate will be persisted to
null? Is that how it works?

Henry Ho

unread,
Mar 8, 2010, 5:26:24 PM3/8/10
to cf-orm-dev
Ya, if it is not in variables scope, it'll be inserted as Null.


Henry

Nando

unread,
Mar 9, 2010, 1:39:04 AM3/9/10
to cf-orm-dev
Thanks very much guys.

Nando

unread,
Mar 9, 2010, 3:52:30 AM3/9/10
to cf-orm-dev
What seems to be a bit odd is that date type fields are set to null automatically if they are submitted as empty strings. I thought that maybe numeric typed fields might be handled in a similar way, but they throw a mismatched type error in Hibernate.

I'm wondering if I should or can depend on this behavior, the empty string to null translation with date fields. Perhaps it would be better to set the fields to null?

Thanks,

Nando



Thanks very much guys.
--
You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
To post to this group, send email to cf-or...@googlegroups.com.
To unsubscribe from this group, send email to cf-orm-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cf-orm-dev?hl=en.




--
Nando M. Breiter
The CarbonZero Project
CP 234
6934 Bioggio
Switzerland

+41 91 606 6372

na...@carbonzero.ch
www.carbonzero.ch

Bob Silverberg

unread,
Mar 9, 2010, 8:31:44 AM3/9/10
to cf-or...@googlegroups.com
I would say yes, if you want to set a db field to null you should set the property to null as well, either explicitly in your application code or via the model (e.g., override the setter to do it). It may work to simply use an empty string, but depending on default behaviour seems a bit dangerous to me.  Your code will also be more self-documenting if you do it yourself.


On Tue, Mar 9, 2010 at 3:52 AM, Nando <d.n...@gmail.com> wrote:
What seems to be a bit odd is that date type fields are set to null automatically if they are submitted as empty strings. I thought that maybe numeric typed fields might be handled in a similar way, but they throw a mismatched type error in Hibernate.

I'm wondering if I should or can depend on this behavior, the empty string to null translation with date fields. Perhaps it would be better to set the fields to null?

Thanks,

Nando




--
Bob Silverberg
www.silverwareconsulting.com

Hands-on ColdFusion ORM Training @ cf.Objective() 2010
www.ColdFusionOrmTraining.com


Reply all
Reply to author
Forward
0 new messages