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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:54:10+00:00 2026-05-11T20:54:10+00:00

I’m looking for an easy way to extend existing JPA mapping. The idea is

  • 0

I’m looking for an easy way to extend existing JPA mapping. The idea is as follows:

I have an EAR project with EJB3+JPA module which has ClassA annotated and mapped to table class_a. But I want some other module (another EJB module) to have ClassB which adds more properties to ClassA (extend?).

One way that I though about, is just to add those additional fields to the class_a table and run non-HQL queries to retrieve that data. It’s not good as I have to do many things by hand: type mapping, column mapping, etc.

I’ve done simple check but it seems that I can’t extend ClassA in the second module (by ClassB) because they use different EntityManagerFactories and some classes from the first module are not seen by the second and vice versa.

I’ve already seen the <jar-file> tag inside persistence.xml. I need something like that, but the use of it requires to have that file listed in the first module and it must exist (It won’t skip if not found). Is there something like that, that can be put on the extending module (second one) and not the extendable one (the first)?

If there’s a way to extend the JPA mapping in run-time it would be great. Is there such a way ? Is there another solution to my problem ?

  • 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-11T20:54:10+00:00Added an answer on May 11, 2026 at 8:54 pm

    The implemented solution is as follows.
    I have one jar and two EJB modules:

    1. The jar is the base one. It holds the base entities and local interface for the extension:

      @Entity
      public class BaseEntity {
          public long id;
          @Id @GeneratedValue
          public long getId() {...
          ... other variables, getters, setters ...
      }
      
      @Local
      public interface EntitiyManagerWithExtendedEntitiesInterface {
          public EntityManager getEntityManager;
      }
      
    2. The first EJB module is the one that will extend the base entities and add EJB to get it’s entity manager. This module also includes persistence.xml with <jar-file>../path_to_first_jar_file.jar</jar-file> line.

      @Entity
      ... discriminator annotations
      public class ExtEntity extends BaseEntity {
          ... additional fields here
      }
      
      @Stateless
      public class EntitiyManagerWithExtendedEntitiesBean implements EntitiyManagerWithExtendedEntitiesInterface {
          @PersitenceContext
          EntityManager em;
          public EntityManager getEntityManager() {
              return em;
          }
      }
      
    3. The second EJB module will have EJBs that need only the jar to compile but require the first EJB to run (require an EJB that will implement EntitiyManagerWithExtendedEntitiesInterface interface).

      @Stateless
      public class getSomeEntity {
          @EJB
          EntitiyManagerWithExtendedEntitiesInterface ext;
          EntityManager em;
          @PostConstruct
          public void injectEntityManager() {
              em = ext.getEntityManager();
          }
          public void ejbInterfaceMethod() {
              ... method that uses em variable (EntityManager)
          }
      }
      

    This way the application server will have to manage the dependencies between modules and I can easily swap the 1st EJB module to include another set of extension entities.

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.