Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6823639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:48:22+00:00 2026-05-26T21:48:22+00:00

I use JPA and Hibernate for my project. I have two classes with same

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:48:23+00:00Added an answer on May 26, 2026 at 9:48 pm

    If you want to create a JPQL query you need to pass the Entity name to it. As you posted, you have 2 entities which are represented by the same Java class, but different Entity name (X_USER explicitly set by you and User set implicitly).

    If you want to get dynamically the name of the entity you should rather use the Metamodel, so something like this should do the work (not checked):

    EntityManager em = ...
    Metamodel model = em.getEntityManagerFactory().getMetamodel();
    String entityName = model.entity(com.your.pckg.User.class).getName();
    

    HTH.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that use both dependencies independently: BoneCP and Hibernate. But thanks
I would like to implement pagination in my Servlet/EJB/JPA-Hibernate project, but I can't figure
i'm working on a project in which i use JPA, Hibernate and all this
I'm currently working on a project that makes use of Seam/Hibernate (JPA) on MySQL.
I use JPA + Hibernate. I have 2 entities (Parent, Child) with OneToMany connection
I use JPA inheritance with JOIN strategy (JPA2/Hibernate). I have an abstract general Event
I have two related entities being mapped by JPA annotations backed by hibernate. The
Is it possible to use/register a Hibernate UserType in a JPA project, where no
I use: EJB3 / JPA (Hibernate) MySQL 5 I have to set up a
i have the following problem. I use Spring and JPA (Hibernate) to persist Data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.