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 219291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:49:51+00:00 2026-05-11T18:49:51+00:00

(note: I’m quite familiar with Java, but not with Hibernate or JPA – yet

  • 0

(note: I’m quite familiar with Java, but not with Hibernate or JPA – yet 🙂 )

I want to write an application which talks to a DB2/400 database through JPA and I have now that I can get all entries in the table and list them to System.out (used MyEclipse to reverse engineer). I understand that the @Table annotation results in the name being statically compiled with the class, but I need to be able to work with a table where the name and schema are provided at runtime (their defintion are the same, but we have many of them).

Apparently this is not SO easy to do, and I’d appreciate a hint.

I have currently chosen Hibernate as the JPA provider, as it can handle that these database tables are not journalled.

So, the question is, how can I at runtime tell the Hibernate implementation of JPA that class A corresponds to database table B?

(edit: an overridden tableName() in the Hibernate NamingStrategy may allow me to work around this intrinsic limitation, but I still would prefer a vendor agnostic JPA solution)

  • 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-11T18:49:52+00:00Added an answer on May 11, 2026 at 6:49 pm

    You need to use the XML version of the configuration rather than the annotations. That way you can dynamically generate the XML at runtime.

    Or maybe something like Dynamic JPA would interest you?

    I think it’s necessary to further clarify the issues with this problem.

    The first question is: are the set of tables where an entity can be stored known? By this I mean you aren’t dynamically creating tables at runtime and wanting to associate entities with them. This scenario calls for, say, three tables to be known at compile-time. If that is the case you can possibly use JPA inheritance. The OpenJPA documentation details the table per class inheritance strategy.

    The advantage of this method is that it is pure JPA. It comes with limitations however, being that the tables have to be known and you can’t easily change which table a given object is stored in (if that’s a requirement for you), just like objects in OO systems don’t generally change class or type.

    If you want this to be truly dynamic and to move entities between tables (essentially) then I’m not sure JPA is the right tool for you. An awful lot of magic goes into making JPA work including load-time weaving (instrumentation) and usually one or more levels of caching. What’s more the entity manager needs to record changes and handle updates of managed objects. There is no easy facility that I know of to instruct the entity manager that a given entity should be stored in one table or another.

    Such a move operation would implicitly require a delete from one table and insertion into another. If there are child entities this gets more difficult. Not impossible mind you but it’s such an unusual corner case I’m not sure anyone would ever bother.

    A lower-level SQL/JDBC framework such as Ibatis may be a better bet as it will give you the control that you want.

    I’ve also given thought to dynamically changing or assigning at annotations at runtime. While I’m not yet sure if that’s even possible, even if it is I’m not sure it’d necessarily help. I can’t imagine an entity manager or the caching not getting hopelessly confused by that kind of thing happening.

    The other possibility I thought of was dynamically creating subclasses at runtime (as anonymous subclasses) but that still has the annotation problem and again I’m not sure how you add that to an existing persistence unit.

    It might help if you provided some more detail on what you’re doing and why. Whatever it is though, I’m leaning towards thinking you need to rethink what you’re doing or how you’re doing it or you need to pick a different persistence technology.

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

Sidebar

Ask A Question

Stats

  • Questions 158k
  • Answers 158k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, you could just replace the '=' with a "\n"… May 12, 2026 at 11:17 am
  • Editorial Team
    Editorial Team added an answer Well, you can do it, but it's ugly. #define ENCODE_STRING_14(str)… May 12, 2026 at 11:17 am
  • Editorial Team
    Editorial Team added an answer How about: text_field_with_auto_complete :currency, :from, { :size => "10", :value… May 12, 2026 at 11:17 am

Related Questions

NOTE: I am not set on using VI, it is just the first thing
NOTE : I mention the next couple of paragraphs as background. If you just
(Note: I realize this is close to How do you document your database structure?
Note: I am just consuming webservice I have no control over webservice code. So
Note - I have not delved very deeply into Apple's iPhone SDK yet. However,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.