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]



Reply via email to