[hibernate-dev] how to get an EntityBinding by class name?

Hardy Ferentschik hardy at hibernate.org
Fri Jul 6 09:53:51 EDT 2012


Hi,

here are some of my thoughts around this.

In Hibernate you can map the same class multiple times using different  entity names. The map of entity bindings kept in Metadata contains 
all entity bindings keyed against these unique names. Trying to look up a binding by class name is not unique and we would have to deal with
multiple bindings. 

>From a JPA perspective you cannot map a class multiple times. You can give it an alternate name via @Entity#name, but that's about it (names
must be unique within the persistence unit). If I am not mistaken atm JPA entities are mapped in the entityBindingMap map using the unqualified
class name (which is probably wrong).

In the source interfaces we have:

EntitySource#getEntityName()
EntitySource#getClassName() 
EntitySource#getJpaEntityName()  // taken from @Entity#name

To be honest I am not 100% sure why we need the explicit #getJpaEntityName(). We need to verify the proper handling of all these names and make
sure we use them appropriately.

Last but not least, looking at @EntityResult I can see that the connection to the corresponding entity is made via a Class reference  (EntityResult#entityClass()), not
by name. I guess that's why you need to this in the lookup in the first place. For this use case iterating seems fair enough for the moment.

--Hardy


On Jul 6, 2012, at 11:28 AM, Strong Liu wrote:

> Hi,
> 
> having a question as $subject.
> 
> the return element (org.hibernate.internal.jaxb.mapping.hbm.JaxbReturnElement) has both entity name and class name attributes, and we are supposed to use one of them to get the target EntityBinding.
> 
> though look up entitybinding by entityname is easy, but I'm not sure how to look up entitybinding by class name, for now, i have used a stupid way, iterator the whole entitybindings within Metadata
> 
> org.hibernate.metamodel.internal.source.annotations.global.SqlResultSetProcessor#bindEntityResult
> 
> wondering if there is a better way to deal with this.
> -------------------------
> Best Regards,
> 
> Strong Liu <stliu at hibernate.org>
> http://about.me/stliu/bio
> 
> _______________________________________________
> 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