I use JPA and Hibernate for my project. I have two classes with same names but in different packages. They are:
@Entity(name = "X_USER")
@Table(name = "X_USER")
public class User {
and:
@Entity
@Table(name="Y_USER")
public class User {
I was creating a search query with: .getSimpleName()
but it didn't work because their simple name are the same. I changed it to .getName()
.
However, it still confuses to which User
to return.
EDIT:
I have that:
SELECT_BY_PROPERTY_QUERY = "SELECT p FROM :CLASS: p WHERE p.:PROPNAME:=?";
and I that:
SELECT_BY_PROPERTY_QUERY.replaceFirst(":CLASS:", clazz.getName()).replaceFirst(":PROPNAME:", propertyName);
and when I debug it it makes something like:
Select p from User p Where p.name=?
It is still User
and it doesn't include package information and returns me wrong User
class.