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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:07:54+00:00 2026-05-17T02:07:54+00:00

How would you configure annotations in the following example code? I’d like to stick

  • 0

How would you configure annotations in the following example code? I’d like to stick with JPA annotations only and avoid Hibernate specific dependencies. Is the code below correct?

@Entity
public class RefExample extends RefData {

}

(There will be multiple versions of these classes, RefSomeOtherExample, etc, and one db table per class. Some may add additional fields (columns) but most will simply make use of the basic fields inherited from the “RefData” base class.)

Base class:

@Entity
public abstract class RefData {

    private long id;
    private String code;
    private String desc;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(unique = true, nullable = false)
    public long getId() {

        return id;
    }

    public void setId(long id) {

        this.id = id;
    }

    @Column(unique = true, nullable = false, length=8)
    public String getCode() {

        return code;
    }

    public void setCode(String code) {

        this.code = code;
    }

    @Column(unique = true, nullable = false, length=80)
    public String getDesc() {

        return desc;
    }

    public void setDesc(String desc) {

        this.desc = desc;
    }
}

Ultimately I’d like to generate schema creation scripts from this using Hibernate’s SchemaExport class. In the case above these two classes should only result in the creation of a single table named “RefExample” with the three columns from “RefData”. Will this work?

  • 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-17T02:07:55+00:00Added an answer on May 17, 2026 at 2:07 am

    From JPA 1.0 specification:

    Both abstract and concrete classes can be entities. Both abstract and concrete classes can be annotated with the Entity annotation, mapped as entities, and queried for as entities.

    Entities can extend non-entity classes and non-entity classes can extend entity classes.

    As you want a single table, you should use Single Table inheritance.

    Just define a discriminator column as follows:

    @Entity
    @DiscriminatorColumn(name="REF_TYPE")
    public abstract class RefData {
    

    But if you do not want to rely on JPA inheritance strategies, you can use MappedSuperclass instead:

    @MappedSuperclass
    public abstract class RefData {
    

    JPA specification

    An entity may inherit from a superclass that provides persistent entity state and mapping information, but which is not itself an entity. Typically, the purpose of such a mapped superclass is to define state and mapping information that is common to multiple entity classes.

    Keep in mind you can not use @Entity and @MappedSuperclass at the same time.

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

Sidebar

Related Questions

I would like to configure JBoss 4.2.x to utilize the JBoss Web Native Connectors
I am using Unity for IOC. I would like to configure the creation of
HttpServletRequest.getRemoteAddr() in Tomcat returns IPv6 formatted IP address, but I would like to configure
I would like to be able to merge two files into one during configure
How can I configure the NppExec plugin for Notepad++? I would like NppExec to
I would like to use hibernate for persisting objects through web services and am
what I would like to accomplish is the following: have autocommit enabled so per
How would I configure my hibernate hbm file to have a last updated date
I would like to use an annotation on a key string to configure the
I would like to get opinion on the best way to manage the following

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.