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

  • SEARCH
  • Home
  • 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 658145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:54:04+00:00 2026-05-13T22:54:04+00:00

I am using JPA and I need to make the tableName a variable. In

  • 0

I am using JPA and I need to make the “tableName” a variable.

In a database, I have many tables, and my code needs to access the table where I specify it to read.

@Entity
@Table(name = "tableName")
public class Database implements Serializable {...............}

Any ideas?

  • 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-13T22:54:04+00:00Added an answer on May 13, 2026 at 10:54 pm

    You can do something like this, if thats your concern, I guess. Never tried it, its just a wild guess. But thats the usual practice — I follow for Named Queries; yes, that’s a different thing altogether.

    @Entity
    @Table(name = Database.tableName)
    public class Database implements Serializable {
        public static final String tableName = "TABLE_1";
        ...............
    }
    

    But I don’t see why anyone would do that. Could you tell us what are you up to? Why you have few tables exactly same definition?

    [Edited]

    I tried your solution. It did not
    work, it says: The value for
    annotation attribute Table.name must
    be a constant expression.

    So, isn’t that clear enough? I mean you can’t do that. And I believe its quite logical. If you want Hibernate to generate your schema then you can define all the entities you want, in the schema, and with the appropriate relationships.

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

Sidebar

Related Questions

I need to create a join table in my database using JPA annotations so
Colleagues, Using JPA I need resolve following issue: at database level exits 3 entities
My application uses JPA to access the backend database. I have a Java class
I have code using JPA and everything works fine in my development environment and
I am writing a batch and using JPA for persistence. I have a table
We are using JPA (hibernate) and have certain tables in a specific schema. I
I need to the get lastest inserted 'product' in my database. I'm using JPA
I'm using Jpa with GAE. I have an Entity with collection of sub Entity
How do I implement the following relationship using JPA? table person ( id int,
I'm using JPA 2 with Hibernate 3.6.8 as the implementation. Let's say we have

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.