[hibernate-dev] how to get an EntityBinding by class name?
Steve Ebersole
steve at hibernate.org
Fri Jul 6 11:12:40 EDT 2012
First, lets just drop "Hibernate entity name" ;) We are talking about
Hibernate development; if we prefixed every Hibernate concept with
HibernateXYZ...
On Fri 06 Jul 2012 09:59:13 AM CDT, Strong Liu wrote:
> okay, let me summary it here and see if i get it correct
>
> 1. entitybinding is keyed by (hibernate) entity name in metamodel
> 2. (hibernate) entity name should be FQN of the entity class (both hbm
> and annotation?)
Not quite... In JPA terms, yes this is always the entity class FQN. In
Hibernate terms it is the explicitly supplied entity-name, or we use
the entity class FQN as the implied value.
> 3. it is correct assumption to throw exception when needs to look up
> an entitybinding but only entity class name provided by mapping and
> there is another entity name mapped to the same entity class
How would you know this? Doing so would require to keep a mapping of
Class->Collection<entityNames} around somewhere which we dont do today
and which I dont feel like we should be doing. If someone supplies
the Class reference as an attempt to look up either metamodel
information or persisters the implication is that the entity name IS
Class#getName. So you simply do the look up based on that and move on.
>
> On Jul 6, 2012, at 10:31 PM, Steve Ebersole wrote:
>
>> Ok, should have gone back to original question
>>
>> Yes, you can name either Class name or entity-name, here. In fact
>> thats true of most of the Hibernate APIs. Its a historical thing.
>> Before Hibernate APIs were just like the JPA APIs in that you could
>> only reference entities by Class reference. With the development of
>> the entity-name feature, thats no longer always possible.
>>
>> We left the Class-reference forms available (non-deprecated) since if
>> your application is not using entity-names that is still a valid way
>> to reference the mappings/persisters because there is a one-to-one
>> correspondence. Otherwise, as already pointed out on this thread,
>> you have a many-to-one correspondence (*a* single Class might
>> reference multiple entity mappings).
>>
>> On 07/06/2012 04: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 athibernate.org <http://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
>>
>>
>>
>> --
>> steve at hibernate.org
>> http://hibernate.org
>
> -------------------------
> Best Regards,
>
> Strong Liu <stliu at hibernate.org <http://hibernate.org/>>
> http://about.me/stliu/bio
>
--
steve at hibernate.org
http://hibernate.org
More information about the hibernate-dev
mailing list