-->
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: AnnotationException: Use of the same entity name twice
PostPosted: Thu Mar 10, 2005 2:02 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Hibernate version: hibernate-3.0rc1, hibernate-annotations-3.0alpha3

I ran into a problem where it appears that you can't have two classes with the same name, even though the classes are in different packages. For example, I tried to do something similar to the following and it gave me an exception of "AnnotationException: Use of the same entity name twice".

The reason why I was trying to do something like this is because I want to have a Person class which is in a base package. This person class will be shared between several different projects. For example, I have one project having to do with reservations and another one having to do with job applications. In the reservations project, a person can have reservations. In the job applications project a person can have job applications. I wanted to make it so that the base level Person class didn't have references to either of these. These would be in the sub-packages. This way, the job applications application would depend on classes in the reservations project and vice versa.

I was thinking it would be nice if Hibernate were able to qualify the internally used names with the package name to avoid conflicts and to allow the use of the same class name in different packages.

The other thing that I was wondering about is that if the subclass Person class (renamed to Person2 to get it to work) didn't have any properties, if it would still create another table, or, if it would just use the base classes table. It appears to be the later which is what I was hoping for.

Code:
// Person.java in mypackage
package mypackage;

public class Person {
...
}

Code:
// Person.java in mypackage/subpackage
package mypackage.mysubpackage;

public class Person extends mypackage.Person {
...
}


Another thing that would be nice is if you add an annotated class to the configuration, that Hibernate automatically adds all the dependent classes.


Top
 Profile  
 
 Post subject: Re: AnnotationException: Use of the same entity name twice
PostPosted: Fri Mar 11, 2005 12:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
jemiller wrote:
"AnnotationException: Use of the same entity name twice".

Use @Entity(name="MyProjectPerson"), I'm constrained by the EJB3 spec here. The defaut value is the unqualified class name.

Quote:
I was thinking it would be nice if Hibernate were able to qualify the internally used names with the package name to avoid conflicts and to allow the use of the same class name in different packages.

Hibernate does that internally, the unqualified class name is an alias for queries.

Quote:
The other thing that I was wondering about is that if the subclass Person class (renamed to Person2 to get it to work) didn't have any properties, if it would still create another table, or, if it would just use the base classes table. It appears to be the later which is what I was hoping for.

It depends your inheritance strategy
SINGLE_TABLE will keep all in 1 table
JOINED will provide 1 table per class and subclass.

Quote:
Another thing that would be nice is if you add an annotated class to the configuration, that Hibernate automatically adds all the dependent classes.

I thought about that, but I'm -1 for now. Annotations can be overridden by XML, plus default import can lead to hard and sneaky user bugs.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 12:18 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Thanks Emmanual, much appreciated.


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.