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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:35:04+00:00 2026-05-26T07:35:04+00:00

My project is a Java Enterprise project and consists of three modules: Assembly (EAR)

  • 0

My project is a Java Enterprise project and consists of three modules:

  • Assembly (EAR)
    • EJB (JAR)
    • Web (WAR)

My domain model resides in the EJB. This includes a Manufacturer class and a Model class. A one-to-many relationship exists between the two. I expose instances of these manufacturers and models through a REST interface that resides in my web project.

Whenever I access one of these manufacturers, the following XML-code is generated:

<manufacturer id=1>
    <name>Ford</name>
    <models>
        <model id=1>
            <name>Fiesta</name>
        </model>
        <model id=2>
            <name>Focus</name>
        </model>
    </models>
</manufacturer>

However, I want it to be like this:

<manufacturer id=1>
    <name>Ford</name>
    <models>
        <model>1</model>
        <model>2</model>
    </models>
</manufacturer>

I have achieved the desired effect by writing a specialized XmlAdapter, ModelAdapter and annotate the field in the Manufacturer class with @XmlJavaTypeAdapter(ModelAdapter.class). This adapter resides in my EJB module as well. A problem arises, however, when a Model needs to be unmarshalled:

private ModelFacade modelFacade;

@Override
public Model unmarshal(Long id) throws Exception {
    return modelFacade.find(id);
}

The ModelFacade, a stateless session bean, can not be injected into the XmlAdapter and the unmarshalling process will therefore always fail.

I have been advised to write a MessageBodyReader in order to be able to “manually” instantiate the adapter and pass the facade as an argument but this specialized message body reader would need to be implemented in the web module. I would very much like contain this behaviour in the EJB module for the simple reason that if I ever decide to create, for instance, a desktop application that depends on the EJB, I don’t need to deal with the same issue again.

In order to achieve this behaviour, I can perform a JNDI lookup in the constructor of the adapter:

public AbstractAdapter(String name) throws NamingException {
    facade = (AbstractFacade<B>) lookup("java:app/MyEJB/" + name);
}

private Object lookup(String name) throws NamingException {
    Context c = new InitialContext();
    return c.lookup(name);
}

and this will work perfectly fine, but I am not sure this is the right way to go. Is doing an JNDI lookup from an EJB module a perfectly fine solution or is there a more favourable one?

  • 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-26T07:35:04+00:00Added an answer on May 26, 2026 at 7:35 am

    You could specify a parameter of type java.io.InputStream on your JAX-RS method (which is on the session bean). Then you could unmarshal that InputStream leveraging JAXB. This would give you the opportunity to configure the javax.xml.bind.Unmarshaller with the appropriate XmlAdapter.

    For More Information

    • https://wink.apache.org/documentation/1.0/html/JAX-RS%20Request%20and%20Response%20Entities.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scenario where the base project consists of java code and web
I'm developing java enterprise web application using EJB 3.1 and I wonder which technology
I'm about to inherit a rather large Java enterprise project that has a large
I am working on a legacy Java Enterprise server project, trying to set up
I create an Enterprise Application CustomerApp that also generated two projects CustomerApp-ejb and CustomerApp-war
I would like to be able to package my jpa-ejb-web project as a standalone
I'm working on an Enterprise project with Java EE 5 and JSF 2.0 (Mojarra
I am currently working on a project with multiple ejb and one ejb-jar.xml. I
I have a project (EJB 3.0, packaged as EAR) with a view (JSF 2.0)
I am working on a legacy Java Enterprise server project, and currently I am

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.