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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:50:36+00:00 2026-05-15T15:50:36+00:00

I have about 10 different entities in my J2EE application that right now share

  • 0

I have about 10 different entities in my J2EE application that right now share the exact same implementation. They all inherit from the same generic abstract class that has been annotated as a @MappedSuperclass, but this class contains none of the implementation I have repeated in all the concrete subclasses.

If I could, I’d put all the various fields and collections on this abstract superclass and therefore put the implementation methods there too — all in one place instead of 10. However, due to JPA restrictions I cannot add JPA annotations to generic fields or accessors.

While I normally favor delegation to implementation inheritance anyway, due to another JPA restriction that says you can’t have an embedded entity with a collection the idea of using a delegate also won’t work.

When I had only 3-4 of these entities and 2-3 methods, it wasn’t a big deal, but now I have about 10 — and about 7-8 methods each…and some of the methods are getting really complex. And the “cut-copy-paste” inheritance I am using really sucks.

Any other brilliant ideas out there?

  • 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-15T15:50:37+00:00Added an answer on May 15, 2026 at 3:50 pm

    It turns out you can use either implementation inheritance or delegation as long as you are sure to use property access mode for your JPA annotations. I was using field access mode for JPA annotations and that was causing me no end of suffering because I could not annotate a generic field type.

    However with property access mode I simply create my generic abstract implementation without annotating it as an entity, mappedsuperclass, embeddable, or anything. This way JPA will ignore it. Then, in the concrete subclasses, I create protected getter and setters methods as needed and put the JPA annotation on those.

    Turned out to be deceptively simple.

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

Sidebar

Related Questions

I have a ListView which displays information about some entities (all of the same
Recently I have read a lot about different NoSQL databases and how they are
I'm learning about packages. I have two classes that are in different packages and
I have read about the different types of reference. I understand how strong, soft
I have a scene in my WPF project with about 2000 different user controls:
I have implemented an IHttpAsyncHandler. I am making about 5 different AJAX calls from
I have a bit of a situation. I've consumed about fourty-eleven different tutorials/books/videos on
i have a general question about properties and ivars. ive seen many different examples
Do I have to put every file in a different folder? like: about-us/about-us.php profile/profile.php
I've seen the information about locating a SQLite database, but I have a different

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.