jsr338-experts@jpa-spec.java.net

[jsr338-experts] Re: [jpa-spec users] Re: Clarification: BindableType

From: Oliver Gierke <ogierke_at_vmware.com>
Date: Thu, 17 Jan 2013 15:16:31 +0100

I am not sure I get the special semantics of Bindable. I digged a bit deeper into what different implementations return for the calls, here's what I found out:

            | BindableType | ….isAssociation() |
------------+--------------------+-------------------+
Hibernate | SINGULAR_ATTRIBUTE | false |
OpenJpa | ENTITY_TYPE | true |
EclipseLink | SINGULAR_ATTRIBUTE | true |
------------+--------------------+-------------------+

This quite a mixed bag (if you wanted to be negative you could call it a mess). At least I think I can reasonably argue that ….isAssociation() is not implemented correctly given the definition of an association in 2.9 of the spec.

I'll refrain from looking into BindableType at all then and just shoot for ….isAssociation() falling back on the persistence attribute type.

Cheers,
Ollie

Am 17.01.2013 um 15:10 schrieb Gordon Yorke <gordon.yorke_at_oracle.com>:

> The issue is that the BindableType is the actual type of the Bindable and has nothing to do with state of the attribute/EntityType. "getBindableJavaType" on Bindable likely extends the confusion and should not be there or renamed to something like getTargetJavaType() but it was added as a shortcut to get the target type without requiring a cast to PluralAttribute.
>
> in your example : ((Attribute)path.getModel()).isAssociation() should return true. You cannot always cast to Attribute without checking instanceof or BindableType first though.
>
> --Gordon
>
> On 17/01/2013 9:46 AM, Oliver Gierke wrote:
>> Hm, from reading the spec naively, would have expected a SingluarAttribute instance for from.get(…).getModel() which then returns a BindableType of ENTITY_TYPE as the path is pointing to an entity.
>>
>> I was under the impression that the separation between Attribute interfaces and BindableType actually exists to allow a flexible mapping. Otherwise I could just do instanceof checks on the actual Attribute type.
>>
>> Also, according to chapter 2.9 of the Spec an attribute with the …ToOne or …ToMany annotations is considered an association. Thus, am I wrong considering the call to ….isAssociation() on my Path pointing to "address" returning false to be a bug then?
>>
>> Cheers,
>> Ollie
>> Am 17.01.2013 um 14:16 schrieb Gordon Yorke <gordon.yorke_at_oracle.com>:
>>
>>> The path in your example is a SINGULAR_ATTRIBUTE, the only time you should expect an ENTITY_TYPE is if the Path<> represents an actual entity like:
>>>
>>> from.getModel().getBinableType() == ENTITY_TYPE
>>>
>>> I do see how this question arises as the specification does not clearly call out when each type should be returned. One has to search the interfaces to see what interfaces extend from Bindable then it becomes clearer.
>>>
>>> --Gordon
>>> On 17/01/2013 8:07 AM, Oliver Gierke wrote:
>>>> Hi all,
>>>>
>>>> the metamodel API exposes a Bindable interface which in turn exposes a BindableType. Unfortunately it doesn't seem to be defined in which cases which BindableType should be returned. E.g. I have the following types:
>>>>
>>>> @Entity
>>>> class Person {
>>>> @OneToOne Address address;
>>>> }
>>>>
>>>> @Entity
>>>> class Address {
>>>> …
>>>> }
>>>>
>>>> Using the Criteria API I now try to find out that a Path instance is starting at Person is pointing to an entity effectively:
>>>>
>>>> Path<?> path = from.get("address");
>>>> BindableType type = path.getModel().getBindableType();
>>>>
>>>> I was expecting to get ENTITY_TYPE returned but I get SINGULAR_ATTRIBUTE from a recent Hibernate. Trying to come up with a bug report for Hibernate I tried to find out what the specified behavior is but couldn't find anything except the rather brief JavaDoc.
>>>>
>>>> Cheers,
>>>> Ollie

-- 
/**
 * @author Oliver Gierke - Senior Member Technical Staff
 *
 * @param email ogierke_at_vmware.com
 * @param phone +49-351-30929001
 * @param fax   +49-351-418898439
 * @param skype einsdreizehn
 * @see http://www.olivergierke.de
 */