Thanks a lot for all of your answers. I just realized that OJB can convert from JDBC types to Number (Integer, Long, BigInteger,BigDecimal) automatically. For example, JDBC type BIGINT can be converted to either primitive long or Object Long without any FieldConversion. In this case, I can just use Long instead of long to solve the problem.
Just wondering anybody can update the document http://db.apache.org/ojb/jdbc-types.html to make that explicit? Thanks, Zhe > > > -----Original Message----- > From: Martin Kal�n [mailto:[EMAIL PROTECTED] > Sent: Wednesday, January 28, 2004 1:04 AM > To: OJB Users List > Subject: Re: How to set null for a column for which > the corresponding > java type is long > > > Danilo Tommasina wrote: > > >> I have a data base column. The data type is > number > >> (10). It is nullable. The JDBC type defined in > >> repository is BIGINT and the corresponding java > type > >> is long (default). Can anybody tell me how to > save a > >> record so that the value of that column is null > >> instead of zero? > > > > Do not use a primitive data type in your > persistent class, use instead a > > subtype of Number. (Integer, Long, BigInteger, > BigDecimal,... ) > > Or; if you don't have control over the bean or want > to keep long, use a > field conversion class that converts long values of > 0 as NULL. > > There are quite a few pre-packaged field conversion > classes that come > with OJB, they can be found in the package: > org.apache.ojb.broker.accesslayer.conversions > > The Int2IntegerFieldConversion class can be used as > a template for how > to write a field conversion for a long with > 0-inserts as NULL. > > See > http://cvs.apache.org/viewcvs.cgi/*checkout*/db-ojb/src/java/org/apache/ojb/ > broker/accesslayer/conversions/Int2IntegerFieldConversion.java?content-type= > text%2Fplain&rev=1.3 > > > To use field conversions, specify them in your > repository. Eg: > > <class-descriptor class="{x}" table="{x}"> > <field-descriptor name="{x}" column="{x}" > jdbc-type="{x}" > > conversion="com.mycompany.PrimitiveLong2LongFieldConversion"/> > > > HTH, > Martin > > -- > Martin Kal�n > Curalia AB Web: http://www.curalia.se > Orrspelsv�gen 2B Mail: [EMAIL PROTECTED] > SE-182 79 Stocksund Tel: +46-8-410 064 40 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > > __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
