-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Annotations always uses fully qualified class name: bug?
PostPosted: Thu Oct 25, 2007 10:24 pm 
Newbie

Joined: Thu Oct 25, 2007 10:14 pm
Posts: 2
Hibernate version: 3.2.3 Annotations: 3.3.0 GA

Mapping documents:

package com.foo.bar;

import ...

@Entity(name="Product")
public class Product {
...
}

Code between sessionFactory.openSession() and session.close():

ClassMetadata mData = sessionFactory.getClassMetadata("Product");

mData is always null whereas

ClassMetadata mData = sessionFactory.getClassMetadata("com.foo.bar.Product");

returns the expected ClassMetadata instance.

Info from debug session

I've debugged the app and traced the problem to:

in org.hibernate.cfg.annotations.EntityBinder:

Code:
   public void bindEntity() {
      persistentClass.setAbstract( annotatedClass.isAbstract() );
      persistentClass.setClassName( annotatedClass.getName() );
      persistentClass.setNodeName( name );
      //persistentClass.setDynamic(false); //no longer needed with the Entity name refactoring?
      persistentClass.setEntityName( annotatedClass.getName() );
      ...
   }


Diagnosis

the annotatedClass is an instance of org.hibernate.annotations.common.reflection.XClass its name correctly shows "Product". However, calling the getName() method on that class returns, instead, the fully qualified class name of the mapped entity: "com.foo.bar.Product".

Is this a bug?

I see the need for the fully qualified class name based on how Hibernate's Session's get(Class class, Serializable id); method is implemented, but it seems to me that one could create two entries in the SessionFactoryImpl's classMetadata Map.

Thanks,

Ezra E.


Top
 Profile  
 
 Post subject: More to the point...
PostPosted: Fri Oct 26, 2007 11:24 pm 
Newbie

Joined: Thu Oct 25, 2007 10:14 pm
Posts: 2
I got a bit far into details. Here's the point:

we specify an entity name in our annotation mappings like so:

Code:
@Entity(name="Product")

and expect that, as with .hbm.xml mappings this will allow us to refer to our entities by this name. According to our reading of the persistence spec it should. Hibernate's annotations, however do not seem to support this.

Any help?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 3:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
unfortunately, the way the spec has been written, hbm name != @Entity.name

So @Entity.name is just an alias for queries.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.