You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by brycenesbitt <br...@obviously.com> on 2007/10/29 04:12:32 UTC

Question: Torque NULL handling on insert, update

Can anyone point me to documentation on what to expect for handling of null
fields.  For foreign key references, I'm having no trouble.  But I have an
int and a long field that set switched from null to 0.  I'd like to find a
way to keep them null.   I do specify:

<column name="RESERVATION_ID"  type="INTEGER" required="false"
default="null"/>

So the column is both not required, and for good measure defaults to null. 
But I don't see corresponding torque code to recognize null as a legitimate
value.
-- 
View this message in context: http://www.nabble.com/Question%3A-Torque-NULL-handling-on-insert%2C-update-tf4709373.html#a13460957
Sent from the Apache DB - Torque Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Question: Torque NULL handling on insert, update

Posted by Thomas Vandahl <tv...@apache.org>.
brycenesbitt wrote:
>    selectCriteria.add(CcsCouponPeer.RESERVATION_ID, (Object)"RESERVATION_ID
> is NULL", Criteria.CUSTOM);

I'd suggest

    selectCriteria.add(CcsCouponPeer.RESERVATION_ID, (Object)null,
	Criteria.IS_NULL);

here.

Bye, Thomas.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Question: Torque NULL handling on insert, update

Posted by brycenesbitt <br...@obviously.com>.
Yep, the docs are lacking.  I got part way there with NULL, and then backed
myself into a corner.  You can process nulls in many cases, just not all of
them.  Ones that work include:

   Criteria selectCriteria = new Criteria();
   selectCriteria.add(CcsCouponPeer.MEMBER_ID,     
member.getMemberIdAsInt(),        Criteria.EQUAL );
   selectCriteria.add(CcsCouponPeer.RESERVATION_ID, (Object)"RESERVATION_ID
is NULL", Criteria.CUSTOM);
   List foo = CcsCouponPeer.doSelect(selectCriteria);

   ....
   updateCriteria.add(CcsCouponPeer.RESERVATION_ID , null);
   CcsCouponPeer.doUpdate(selectCriteria, updateCriteria);

But if you let the mapper update such a row, you'll get torqued.


Greg Monroe wrote:
> 
> Patrick is correct, primitives don't allow for NULL values
> to be used.  FYI, there is also a defaultJavaType attribute
> on the Database element that can be used to change all the 
> getter/setter methods to objects.
> 
> FWIW, primitive is the "default" because it's generally 
> more convenient for code writers to have native types 
> than creating native objects all the time.  
> 
> That said, you're right in that how to deal with NULLs 
> is not well documented.  In addition, one of the ToDo's
> for 4.0 is to improve on how these are handled (e.g. have
> an isNull() test and a way to set a null value if using
> primitives.
> 

-- 
View this message in context: http://www.nabble.com/Question%3A-Torque-NULL-handling-on-insert%2C-update-tf4709373.html#a13470797
Sent from the Apache DB - Torque Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Question: Torque NULL handling on insert, update

Posted by Greg Monroe <Gr...@DukeCE.com>.
Patrick is correct, primitives don't allow for NULL values
to be used.  FYI, there is also a defaultJavaType attribute
on the Database element that can be used to change all the 
getter/setter methods to objects.

FWIW, primitive is the "default" because it's generally 
more convenient for code writers to have native types 
than creating native objects all the time.  

That said, you're right in that how to deal with NULLs 
is not well documented.  In addition, one of the ToDo's
for 4.0 is to improve on how these are handled (e.g. have
an isNull() test and a way to set a null value if using
primatives.

> -----Original Message-----
> From: patrick.carl@web.de [mailto:patrick.carl@web.de] 
> Sent: Monday, October 29, 2007 9:05 AM
> To: Apache Torque Users List
> Subject: Re: Question: Torque NULL handling on insert, update
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I think that null values are not supported for primitive types.
> But you can change your schema to use objects instead of 
> primitive types
> for certain colums by setting the javaType attribute to object.
> See
> http://db.apache.org/torque/releases/torque-3.3/generator/sche
> ma-reference.html
> within the column section.
> 
> Patrick
> 
> brycenesbitt schrieb:
> > But SQL has an additional state:: null.  And there's a 
> difference between
> > calling a torque set method, and not calling a set method.  
> So the question
> > remains: is Torque's behavior documented?  Does Torque 
> support null column
> > values for primitive type columns (e.g. columns other than 
> String and
> > NumberKey)?
> > 
> > 
> > 
> >> What you find here is the Java default behavior. A int has 
> a default
> >> value of 0. It can not be set to null. Therefore when the value is
> >> initialized and no other value is given it is set to 0. 
> Same applies to
> >> long.
> >>
> > 
> 
> - --
> Patrick Carl
> mailto:patrick@carl.it                                http://carl.it
> GnuPG-Fingerprint: 3599 02CF 0419 BCA6 6BAC 4B53 DB7C 1897 451C F498
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> 
> iD8DBQFHJdp723wYl0Uc9JgRAj4hAJ4gtkd7rU/N2vPUEd5jwZGbj91BKwCgvl1x
> AFOghNKPt0YNyMSjX2EYabU=
> =1MN0
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 
> 
DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Question: Torque NULL handling on insert, update

Posted by Patrick Carl <pa...@web.de>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I think that null values are not supported for primitive types.
But you can change your schema to use objects instead of primitive types
for certain colums by setting the javaType attribute to object.
See
http://db.apache.org/torque/releases/torque-3.3/generator/schema-reference.html
within the column section.

Patrick

brycenesbitt schrieb:
> But SQL has an additional state:: null.  And there's a difference between
> calling a torque set method, and not calling a set method.  So the question
> remains: is Torque's behavior documented?  Does Torque support null column
> values for primitive type columns (e.g. columns other than String and
> NumberKey)?
> 
> 
> 
>> What you find here is the Java default behavior. A int has a default
>> value of 0. It can not be set to null. Therefore when the value is
>> initialized and no other value is given it is set to 0. Same applies to
>> long.
>>
> 

- --
Patrick Carl
mailto:patrick@carl.it                                http://carl.it
GnuPG-Fingerprint: 3599 02CF 0419 BCA6 6BAC 4B53 DB7C 1897 451C F498
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)

iD8DBQFHJdp723wYl0Uc9JgRAj4hAJ4gtkd7rU/N2vPUEd5jwZGbj91BKwCgvl1x
AFOghNKPt0YNyMSjX2EYabU=
=1MN0
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Question: Torque NULL handling on insert, update

Posted by brycenesbitt <br...@obviously.com>.
But SQL has an additional state:: null.  And there's a difference between
calling a torque set method, and not calling a set method.  So the question
remains: is Torque's behavior documented?  Does Torque support null column
values for primitive type columns (e.g. columns other than String and
NumberKey)?



> What you find here is the Java default behavior. A int has a default
> value of 0. It can not be set to null. Therefore when the value is
> initialized and no other value is given it is set to 0. Same applies to
> long.
> 

-- 
View this message in context: http://www.nabble.com/Question%3A-Torque-NULL-handling-on-insert%2C-update-tf4709373.html#a13462606
Sent from the Apache DB - Torque Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Question: Torque NULL handling on insert, update

Posted by Patrick Carl <pa...@web.de>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



brycenesbitt schrieb:
> Can anyone point me to documentation on what to expect for handling of null
> fields.  For foreign key references, I'm having no trouble.  But I have an
> int and a long field that set switched from null to 0.  I'd like to find a
> way to keep them null.   I do specify:
> 
> <column name="RESERVATION_ID"  type="INTEGER" required="false"
> default="null"/>
> 
> So the column is both not required, and for good measure defaults to null. 
> But I don't see corresponding torque code to recognize null as a legitimate
> value.

What you find here is the Java default behaviour. A int has a default
value of 0. It can not be set to null. Therefore when the value is
initialized and no other value is given it is set to 0. Same applies to
long.

Patrick

- --
Patrick Carl
mailto:patrick@carl.it                                http://carl.it
GnuPG-Fingerprint: 3599 02CF 0419 BCA6 6BAC 4B53 DB7C 1897 451C F498
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)

iD8DBQFHJYUD23wYl0Uc9JgRAloVAJ9Wz6oXNvRdli/9os87Rd9p8i35jQCgsXsQ
XLtf//nqKcOKmyhMDA+Mi48=
=cev8
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org