You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by ZZZ Liu <z2...@yahoo.com> on 2004/01/28 05:05:08 UTC

How to set null for a column for which the corresponding java type is long

Hi, All

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?

Thanks,
Zhe

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

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


Re: How to set null for a column for which the corresponding java type is long

Posted by Martin Kalén <ma...@curalia.se>.
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: info@curalia.se
SE-182 79  Stocksund    Tel:  +46-8-410 064 40


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


Re: Joins

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi Ankur,

Ankur Gupta wrote:
> I am trying to run a direct SQL query using OJB and not sure how to make
> it work. The query I am trying to run is a join of 2 classes. I haven't
> specified any join mappings in the repository file. Want to do this
> manually. Can you please provide me an example on how to do this
> specific thing?

Hope this will help you

http://db.apache.org/ojb/faq.html#Is it possible to perform my own 
sql-queries in OJB?

regards,
Armin

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



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


Joins

Posted by Ankur Gupta <an...@coreconcept.com>.
I am trying to run a direct SQL query using OJB and not sure how to make
it work. The query I am trying to run is a join of 2 classes. I haven't
specified any join mappings in the repository file. Want to do this
manually. Can you please provide me an example on how to do this
specific thing?


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


Re: How to set null for a column for which the corresponding java type is long

Posted by Andrei Ivanov <an...@ines.ro>.
But isn't that much slower?

/me is a newbie in java and ojb

On Wed, 28 Jan 2004, Danilo Tommasina wrote:

> Hi,
> 
> Do not use a primitive data type in your persistent class, use instead a 
>   subtype of Number. (Integer, Long, BigInteger, BigDecimal,... )
> 
> 
> cheers
> Danilo
> 
> > Hi, All
> > 
> > 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?
> > 
> > Thanks,
> > Zhe
> > 
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! SiteBuilder - Free web site building tool. Try it!
> > http://webhosting.yahoo.com/ps/sb/
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

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


Re: How to set null for a column for which the corresponding java type is long

Posted by Danilo Tommasina <dt...@risksys.com>.
Hi,

Do not use a primitive data type in your persistent class, use instead a 
  subtype of Number. (Integer, Long, BigInteger, BigDecimal,... )


cheers
Danilo

> Hi, All
> 
> 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?
> 
> Thanks,
> Zhe
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free web site building tool. Try it!
> http://webhosting.yahoo.com/ps/sb/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 


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