users@jpa-spec.java.net

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

From: Oliver Gierke <ogierke_at_vmware.com>
Date: Thu, 17 Jan 2013 14:46:46 +0100

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
 */