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=2350219According 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?