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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:20:10+00:00 2026-05-24T21:20:10+00:00

I have a generic Database structure which can store several user-defined records. For example,

  • 0

I have a generic Database structure which can store several user-defined records. For example, the main table is RECORD and the columns are STRING01, STRING02, […], NUM01, NUM02 etc.

I know this is a bit weird, but it has advantages as well as disadvantages. However, this structure exists and can’t be changed. Now I want to create some JPA classes.

First, I created an abstract class RECORD as follows (the Annotations are placed on the gettersthe example is just simplified):

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.STRING)
public abstract class Record {
    @Id
    private long id;

    @Column(name="STRING01")
    private String string01;

    @Column(name="STRING02")
    private String string02;

    @Column(name="NUM01")
    private BigDecimal num01;
}

Then, I created specific classes inherited from RECORD:

@Entity
@DiscriminatorValue("Person")
public class Person extends Record {
    @Transient
    public String getFirstName() {
        return getString01();
    }

    public void setFirstName(String name) {
        setString01(name);
    }

    @Transient
    public BigDecimal getWeight() {
        return getNum01();
    }

    public void setWeight(BigDecimal weight) {
        setNum01(weight);
    }
}

This works fine, as I can query RECORD for a PERSON’s primary key (via EntityManager.find()) and get a Result as instance of PERSON. I can query for FirstName and Weight without having to know the generic column names.

However, if I write my own JPA Query like SELECT p FROM Person p WHERE p.firstName = 'Michael', it fails. firstName is transient, and here I have to use the generic name string01.

Is there some way of overriding the base class’ attribute name in JPA? Maybe there’s a vendor-specific solution (I’m using EclipseLink)?

  • 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-24T21:20:10+00:00Added an answer on May 24, 2026 at 9:20 pm

    You can try and map multiple attributes to the same column.
    The additional attribute would then be annotated with @Column( name = "column name", insertable = false, updatable = false, nullable = false ).

    Alternatively, you might be able to replace/enhance the JPQL resolver in order to internally map p.firstName to p.string01, but that would be EclipseLink specific, and I don’t really know if that’s even possible. Take this as just a hint what to look for.

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

Sidebar

Related Questions

I have generic list which must be a preserved order so I can retrieve
currently I'm trying to have a setup where a generic database is distributed to
Is there any name for the following DB table design: Basically we have generic
We have a normalized SQL Server 2008 database designed using generic tables. So, instead
I have a class, Order, which I persist to a database using NHibernate. There
I currently have a Generic method that reads an Value from the database based
I have a many-to-many structure in place in my database / Entity Framework model.
I have generic type that looks like: public class GenericClass<T, U> where T :
I want to write in Delphi (2009 - so I have generic dictionary class)
I am aware of Web Services and WCF but I have generic question with

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.