-->
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: Annotationens and Renaming of the Entity-Name: impossible?
PostPosted: Tue Jun 22, 2010 1:01 pm 
Beginner
Beginner

Joined: Thu Oct 04, 2007 12:22 pm
Posts: 48
I am using for my hibernate classes annotations and have to set the entity name manually.
At first I thought it would be enough to set @Entity(name="MyEntityName"). But Hibernate
ignores that and still uses the fully qualified class name. While searching the forum I discovered
this post:

https://forum.hibernate.org/viewtopic.php?p=2350219

According to that there exist any reasons that the entity name from the annotation is not used
in criterias (but for strange reasons it works in HQL).

My next try was to set the entity via access method. As test I used the following code snippet.
I only retrieve the matching PersistentClass from the hibernate configuration, set the entity name
anew, print it out for being sure and then search within the configuration for the new named entity
class:

Code:
Iterator<org.hibernate.mapping.PersistentClass> it = hibernateConfiguration.getClassMappings();
while(it.hasNext())
{
  org.hibernate.mapping.PersistentClass pc = it.next();
  if(pc.getClassName().equals(MyAnnotatedClass.class.getName()))
  {
    pc.setEntityName("NewEntityName");
    System.out.println(pc.getEntityName());
  }
}

System.out.println(hibernateConfiguration.getClassMapping("NewEntityName"));


Although the entity name is taken (output in the loop) the last line does not result in
my class but in a null reference. Can anyone explain why? Or is there any other possibility?


Top
 Profile  
 
 Post subject: Re: Annotationens and Renaming of the Entity-Name: impossible?
PostPosted: Thu Jun 24, 2010 5:03 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
What exactly do you want to achieve or what is your concrete problem?


Top
 Profile  
 
 Post subject: Re: Annotationens and Renaming of the Entity-Name: impossible?
PostPosted: Thu Jun 24, 2010 10:10 am 
Beginner
Beginner

Joined: Thu Oct 04, 2007 12:22 pm
Posts: 48
In my project I work mainly with entity names rather than with the (full qualified) class name,
because they are in some cases determined dynamically by the application.

Therefore my DAOs use for the creation of all criterias a getEntityName() method, which returns
the the system name of the entity, which is identical to the Hibernate entity name.
So no matter what the reasons are, it is important for the application to use only the entity name
in all statements (queries and criteria).

The problem now arises when an entity name is expected, but Hibernate does only resolve classes
by its full qualified class name. So there is a big gap between the possibilities with xml-mapping
(there the entity name can be set and is used by Hibernate) and the entity-name management of
the annotation approach.

I really hate the thought of dumping the annotations and return to the xml mapping only because of
this problem.


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.