[hibernate-dev] Fwd: Re: Proxies and typing

Sanne Grinovero sanne at hibernate.org
Wed Mar 21 06:36:01 EDT 2012


As an API user if I'm expected to use the _User_ interface, I think I
would expect the annotations to be defined on the interface, not on
the UserImpl.class .. as with the rest of mapping annotations.

I don't know about the technical requirements to make this
implementable; I guess you need some UserImpl class as a prototype?

If so wouldn't it make sense to have

@Entity @PrototypedBy(UserImpl.class)
public interface User {

 @Id Long getUserId();
   void setUserId(Long id);

}

public class UserImpl implements User {
   ...
}

And ideally I would expect the "prototype" class to be not needed / optional.

Finally, since I'd expect the setter / getter implementations in the
proxy to be generated by us, could we have them take care of
bi-directional relations, to update both sides of relation
automatically and correctly? I was speaking recently to a Ruby
developer who just switched to JavaEE, and he pointed out that this
requirement is long gone in other persistence APIs.
I know by experience this also frequently bites beginners, and even
experienced developers have to write code about this.. this looks like
a chance to evolve?

Sanne



On 21 March 2012 01:19, Steve Ebersole <steve at hibernate.org> wrote:
> Forwarding a part of this discussion that got inadvertently limited to
> just Sanne and myself.
>
> Bringing this back up because this is most likely not going to be
> accepted into JPA 2.1.  Anyway, I am all for going down the path that:
>
> public interface User {
> ...
> }
>
> @Entity
> @Proxy(proxyClass=User.class)
> public class UserImpl implements User {
>     ...
> }
>
>
> means that users would use User.class in all phases of the API:
> User user = session.byId( User.class ).get( 1 );
> EntityType<User> jpaEntityType = emf.getMetamodel().entity(User.class );
> etc.
>
> I think that is the cleanest path that allows generic-typed api.
>
>
> -------- Original Message --------
> Subject: Re: [hibernate-dev] Proxies and typing
> Date: Thu, 26 Jan 2012 14:37:22 +0000
> From: Sanne Grinovero <sanne at hibernate.org>
> To: Steve Ebersole <steve at hibernate.org>
>
> On 26 January 2012 14:02, Steve Ebersole <steve at hibernate.org> wrote:
>> These emails are just between you and me.  Not sure if thats what you
>> intended.  I erroneously replied to just you at one point but then sent to
>> whole list also.  Anyway, just mentioning...
>
> Ah, sorry, didn't notice either. Well last reply then, will try resume
> the public conversation if I have more comments.
>
>> The idea of requiring the interface is appealing in a way.  But, for
>> example, there are odd inconsistencies then.  For example
>>
>> User user = session.byId( User.class ).get( 1 );
>>
>> but then
>>
>> EntityType<UserImpl> jpaEntityType = emf.getMetamodel().entity(
>> UserImpl.class )
>>
>>
>> Which I guess is my biggest hang up.  On one side we are saying that the
>> impl is the entity and on the other saying the interface is the entity.
>>
>> You know me and consistency :)
>
> I agree on consistency, but this is tricky, I'm not sure if you need
> the UserImpl at all, maybe you can remove it from the MetaModel (maybe
> after having read out other metadata from it).
>
> Isn't such a mapping definition like a dirty workaround to actually
> map the interface ?
>
> Sanne
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev




More information about the hibernate-dev mailing list