• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: BigDecimal WOes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BigDecimal WOes


  • Subject: Re: BigDecimal WOes
  • From: Chuck Hill <email@hidden>
  • Date: Sat, 22 Nov 2008 19:11:03 -0800


On Nov 22, 2008, at 6:44 PM, Neil MacLennan wrote:

I'm having trouble with BigDecimal, WO and my database. You know how some people have trouble with dates amd time zones? Well I've never quite mastered the finer idiosyncrasies of floating point numbers in Java.

I have an EO attribute, 'amount' -- a currency value you'll not be surprised to hear. It's decimal field in my database (MySQL) and a BigDecimal in my model.

I'm aware of "issues" with BigDecimal when you use the BigDecimal(double) contructor and so I've been using the better BigDecimal(String) constructor.

When I first insert my EO (containing "amount") and saveChanges -- it works fine. The value in the DB is as expected, say, 16.16, representing 16 pounds and 16 pence.

When I next come to update that row I get a JDBC error and an EOGeneralAdaptorException failure.

I turned on logging in MySQL (Wonder SQL logging wasn't too helpful) to see what was happening: the UPDATE transaction is being rolled back because the row could not be sucessfully updated. Here's why:

[MySQL Log]
2 Prepare [4] UPDATE OrderTicket SET paymentStatus = ? WHERE (ticketID = ? AND amount = ? AND orderID = ? AND paymentStatus = ? AND paymentTimestamp is NULL AND shopID = ?)


2 Execute [4] UPDATE OrderTicket SET paymentStatus = 'Authorising with Provider...' WHERE (ticketID = 5824 AND amount = 16.159999847412 AND orderID = 127 AND paymentStatus = 'Taking Card Details...' AND paymentTimestamp is NULL AND shopID = 3)

2 Query       rollback
[END]

For some reason, WO is using this imprecise floating value (16.159999847412) in the DB lock to UPDATE against. But I'm stumped where it's getting this from. Is it reading it back in again from the DB at some point and because the database has the "amount" field as a decimal it's using the BigDecimal(double) contructor? Should I only use string (varchar/char) db fields for use with BigDecimal?

I've "fixed" the issue by not having WO lock on the amount attribute in my model, but that doesn't fix the underlying problem: it just avoids it. What's the real answer?


How is the attribute defined in the model? It sounds like the value type might be wrong.

Chuck

--
Chuck Hill             Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects







_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: BigDecimal WOes
      • From: Neil MacLennan <email@hidden>
References: 
 >BigDecimal WOes (From: Neil MacLennan <email@hidden>)

  • Prev by Date: BigDecimal WOes
  • Next by Date: Re: EO Table creation failing
  • Previous by thread: BigDecimal WOes
  • Next by thread: Re: BigDecimal WOes
  • Index(es):
    • Date
    • Thread