cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aristedes Maniatis <...@maniatis.org>
Subject Re: SQL UPDATE fires on non-primitive values
Date Thu, 19 Jun 2014 07:23:07 GMT
We solved this issue by subclassing Number as Money, which for us forces 2 decimals and does
a couple of other nice things with arithmetic that makes sense for money calculations, and
constructors like Money(dollars, cents) which we found useful.

We then added that type directly to the Cayenne model, thereby enforcing our rules about rounding
and arithmetic, and ensuring we didn't use the wrong scale for a BigDecimal somewhere by mistake.

Ari


On 19/06/2014 6:22am, Mark Stobbe wrote:
> @Andrus: Yes. I tested using an object which has a decimal column with
> scale 5. I retrieve the object, if you check the value returned it has
> scale 5. Next I set the value to BigDecimal.ZERO, if you check the value it
> has scale 0.
> Then if you check in the isNoop method you will see that the two decimals
> are not the same because their scale is 5 and 0.
> 
> @Michael: Yes, this was also what I was thinking about. Of course it means
> I will have to use the same scale for all decimals (in principal not a big
> deal). It's good to know that others have encountered the same issue! :-)
> 
> 
> On Wed, Jun 18, 2014 at 3:13 PM, Andrus Adamchik <andrus@objectstyle.org>
> wrote:
> 
>> How do you set the values?
>>
>> object.setXyz(new BigDecimal(..)) ?
>>
>> On Jun 18, 2014, at 3:56 PM, Mark Stobbe <markstobbe85@gmail.com> wrote:
>>
>>> Thank you for the link to the code that does the check.
>>>
>>> I figured out that if two BigDecimal do not have the same scale, they are
>>> considered different. I guess that makes sense.
>>>
>>> When I retrieve BigDecimals from Cayenne it will have the correct scale
>>> set, but it does not set the scale of the new value before it compares.
>>> Is this something that Cayenne can solve?
>>>
>>> Mark
>>>
>>>
>>>
>>> On Wed, Jun 18, 2014 at 8:29 AM, Andrus Adamchik <andrus@objectstyle.org
>>>
>>> wrote:
>>>
>>>> Actually even if an object is marked as dirty after ‘setXyz’, later on
>>>> during commit Cayenne should do a proper comparison and avoid “phantom”
>>>> commits. The relevant code is in
>>>> org.apache.cayenne.access.ObjectDiff.isNoop:
>>>>
>>>>
>>>>
>> https://github.com/apache/cayenne/blob/master/cayenne-server/src/main/java/org/apache/cayenne/access/ObjectDiff.java
>>>>
>>>> Andrus
>>>>
>>>>
>>>> On Jun 18, 2014, at 12:03 AM, Mark Stobbe <markstobbe85@gmail.com>
>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I have a decimal column which is translated to a BigDecimal. When the
>>>> value
>>>>> is equal to 0 and I set the value equal to 0 again, it will actually
>>>>> perform a SQL UPDATE. The two objects are "==", but they are "equals".
>>>>> In the source I found in de PersistentObjectHolder.setValue the
>>>> following:
>>>>>
>>>>> Object oldValue = setValueDirectly(value);
>>>>> if (oldValue != value && relationshipOwner.getObjectContext()
!= null)
>> {
>>>>> relationshipOwner.getObjectContext().propertyChanged(relationshipOwner,
>>>>> relationshipName, oldValue, value);
>>>>> ..
>>>>> }
>>>>>
>>>>> Is this piece of code used for non-primitive properties?
>>>>>
>>>>> Mark
>>>>>
>>>>> PS: I am using 3.2M1
>>>>
>>>>
>>
>>
> 

-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Mime
View raw message