persistence@glassfish.java.net

Re: code review for issue 1388

From: Markus Fuchs <Markus.Fuchs_at_Sun.COM>
Date: Thu, 09 Nov 2006 08:03:36 -0800

Hi Jielin,

you don't have to check for null, when using instanceof:

< // it should be either QueryKeyExpression or
ExpressionBuilde
< if ((base != null) && (base instanceof
ExpressionBuilder)) {

Thanks,

-- markus.

jielin wrote:

> Hi, Tom,
>
> Attahced is the fix for issue 1388. Could you please review the fix?
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=1388.
>
> The problem is that a bulk UPDATE statement setting a field of an
> embedded instance changes a column mapped to a field of the entity
> instance, if the field of the embedded instance has the same name as a
> field of the entity. So
>
> Query "UPDATE Customer c SET c.country.name = 'CHANGED'" generates
> "UPDATE CUSTOMER_TABLE SET NAME = 'CHANGED'"
> instead of "UPDATE CUSTOMER_TABLE SET COUNTRY_NAME = 'CHANGED'"
>
> The causing is in ExpressionQueryMechanism:prepareUpdateAll(). When
> mapping field to column, the following code is only taking field name
> as a string argument.
> field =
> getDescriptor().getObjectBuilder().getFieldForQueryKeyName(fieldExpression.getName());
>
> So 'c.country.name' is only passing 'name', once there is field name
> matching at the class level, it will return the column.
>
> The fix for this is before calling the above code, check if the field
> is at class level.
> Tested with entity-persistence-tests.
>
> Thanks.
>
> Jielin