Skip to main content

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

  • From: Gordon Yorke <gordon.yorke@...>
  • To: jsr338-experts@...
  • Subject: [jpa-spec users] [jsr338-experts] Re: Re: Clarification: BindableType
  • Date: Thu, 17 Jan 2013 10:10:56 -0400
  • List-id: <jsr338-experts.jpa-spec.java.net>

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@...>:

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



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

Oliver Gierke 01/17/2013

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

Oliver Gierke 01/17/2013

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

Gordon Yorke 01/17/2013

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

Oliver Gierke 01/17/2013

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

Gordon Yorke 01/17/2013

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

Oliver Gierke 01/17/2013
 
 
Close
loading
Please Confirm
Close