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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:39:00+00:00 2026-06-07T17:39:00+00:00

Being completely new to Enterprise Java development and after reading the following tutorial.I managed

  • 0

Being completely new to Enterprise Java development and after reading the following tutorial.I managed to develop my first session bean. After reading a little about session beans I do have some questions about it (session bean) and I hope the experts out here could help me out.

Normally in a servlet scenario without using EJB we would do something like the following to accomplish a certain task

 StudentList stud = businesslayer.businessMethod_GetStudentsFromDb(); 

Now the businesslayer would call the service layer which would get the details from the DB and return it.

Now my questions are as follows:

1-If I were to implement this mechanism using say a stateless EJB will I have to copy the domain package which contains the domain object StudentList to the “-ejb” folder of my enterprise project (I am using netbeans).Similarly will I have to copy other Business methods from the source folder of my “-war” folder to the ejb folder just so that the stateless bean in the “-ejb” folder can use those methods. Cant classes inside the “-ejb” folder use classes insider the source folder of the “-war” folder.

2-This is the question so far i could not understand. What advantage would i get if i used EJBs instead of my current mechanism ?

  • 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-06-07T17:39:02+00:00Added an answer on June 7, 2026 at 5:39 pm

    1

    If you’re building a single application, there’s nothing you need to copy. If you want to have a very strict separation between business code and web/view code you can create an ear, with an ejb module and a web module. All classes in the web module can access all classes in ejb module, but the reverse is not true. This effectively imposes a layering in your application.

    But you don’t have to go for this separation. You can also just put your EJB beans in a single war together with your Servlets and what have you. There’s no restriction on where you put your beans. It can be in a separate package, or in the same package as your Servlets.

    You might wanna look at this example I made: http://arjan-tijms.omnifaces.org/2011/08/minimal-3-tier-java-ee-app-without-any.html. There, BusinessBean is an EJB that resides in the same (default) package as the JSF backing bean in a single war.

    In the single war setup, everything can access everything. Do note that even in this situation you probably would like to keep your business code “clean” and keep things like HttpRequest and such out of it.

    2

    EJB beans, especially EJB light, provide exactly those things that most every web application needs: transactions, pooling, thread-safeness, security and injection. You’ll get the most out of EJB beans when combined with JPA. The advantage is that your code will be much less verbose and at the same time shielded from race conditions and inconsistencies that you’ll run into when using plain JDBC.

    E.g.

    @Stateless 
    public class CustomerService { 
    
      @PersistenceContext 
      private EntityManager entityManager; 
    
      public void addCustomer(Customer customer) { 
        entityManager.persist(customer); 
      } 
    }
    

    Without EJB you’ll need a bunch of try/finally blocks which open and close the connection, start and commit the transaction etc. And without JPA you’ll have a large block of tedious code that inserts individual fields of the Customer entity shown in the example into a prepared statement.

    If you (later) have services that call one or more other services and either everything needs to be saved to the DB or nothing (as opposed to something undefined in between), then this is quite a challenge to accomplish in plain JDBC. You’ll have to pass open connections around and need special variants of each service method that opens/closes connections and starts/commits transactions in addition to methods that can be used in an intermediate phase. Before long, this will become highly complex and a big ball of mud.

    With EJB, every method in an EJB bean that you call from within an other EJB bean automatically joins the ongoing transaction or starts its own if no transaction is in progress. This alone massively simplifies many common business tasks carried out by typical web applications.

    Don’t let anyone tell you that only “enterprise applications” need transactions, and web applications don’t need this. This is simply not true. A transaction is a very basic thing when doing DB operations, at the same level of basic requirements as primary keys or foreign keys are. When performing business logic for say an order (in a webshop), you definitely don’t want your inventory being decremented, but no actual order being send, or an order being send but no money subtracted from your customer’s account, etc etc. The simplest of business logic often involves writing to at least two tables, and every time that happens you’d better be using transactions.

    Do make sure you’re using EJB 3 though. Stay far away from everything that has to do with EJB 2. Don’t even touch things like home interfaces or Entity Beans, which have been deprecated for some 6 years now. (don’t confuse EJB Entity Beans with JPA Entities though, despite the unfortunate name similarity these are completely different. JPA Entities are very sane and useful)

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

Sidebar

Related Questions

Being completely new to Java EE (but not to Java itself) I'm trying to
Being new to SQLAlchemy, I was wondering at what time would Session() should be
Being new to OpenCL i would like to know if the following scenario is
being completely new to the Sharepoint scene, I was wondering what basic solutions are
For starters, I am completely new to PHP. That being said, here's my problem.
I am completely new to Java and have an assignment coming up; with the
this seems to be an easy task really, but being completely new to the
I come from a .NET background and am completely new to Java and am
Being completely new to WCF, I'm trying to make a RESTful service which will
I am completely new to java, but I have urgent requirement to create a

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.