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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:18:09+00:00 2026-05-26T20:18:09+00:00

I have a ConfigParameter SLSB that reads configuration values from the ejb-jar.xml file. This

  • 0

I have a ConfigParameter SLSB that reads configuration values from the ejb-jar.xml file.

This class has only private fields and for each field a corresponding getter method. In my application I have a lot of other EJBs that use an instance of ConfigParameter to read the configuration values.

Now, I thought it would be good idea to make ConfigParameter a @Singleton, since its state is shared across the whole application.

But in the ejb-jar.xml I can set session-type only to Stateful or Stateless. The file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
  <enterprise-beans>    
    <session>
      <ejb-name>ConfigParameter</ejb-name>
      <ejb-class>myapp.util.ConfigParameter</ejb-class>      
      <session-type>Stateless</session-type> <!-- make this a Singleton -->
      <env-entry>
        <env-entry-name>adminRoleName</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>admin</env-entry-value>
      </env-entry>
    </session>
  </enterprise-beans>
</ejb-jar>

My questions are:

  1. Is it a good idea to make this bean a singleton?
  2. If yes, how can I achieve this?
  3. For understanding: Why is it not allowed to set session-type to Singleton?
  • 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-26T20:18:10+00:00Added an answer on May 26, 2026 at 8:18 pm

    You’re using EJBs 3.0. Singleton EJBs were introduced in EJB 3.1. If you want to define it in ejb-jar.xml you should define appropriate version (note the version attribute and XSD location changed to 3.1)

    <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" 
        version="3.1">
    

    Or just use @Singleton annotation on the EJB class itself.

    And yes – I would definitely say that it’s appropriate to mark application-wide configuration bean as Singleton.

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

Sidebar

Related Questions

Have a LinqtoSql query that I now want to precompile. var unorderedc = from
Have a slight problem. Trying to post XML to a server. To do this,
Have you managed to get Aptana Studio debugging to work? I tried following this,
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
Have created simple Ajax enabled contact forms before that have around 12 fields -
Have a simple console app where user is asked for several values to input.
Have some data in a sybase image type column that I want to use
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE

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.