How To Use Ejb


There's a fair few projects out there using Enterprise Java Beans. What are the issues and decisions that people are facing and making? Populate this page with links to pages discussing various problems.

If you are building system with EJB, Entity Beans are a new kind of animal. They are nice, but what is the best way to use them?

In particular how do you work with Entity Beans and business logic? I've heard of two approaches: Entity Beans As Domain Objects and Entity Beans As Data Gateways.

Choice of Application Server

Our biggest issues are which Application Server is the right one? How does one go about Picking An Ejb Server?

Unit testing enterprise beans

Unit testing in Java is quite straightforward except for the GUI parts. Facing development of Enterprise Java Beans it becomes harder to make sensible tests. See Ejb Unit Test for a further discussion about this.



Biggest problem with Entity Beans � marketing. Most people have the impression that Entity Beans are some kind of O/R mapping tool (RDBMS). NO! They were designed as a universal persistence layer. Even CMP should not be considered as an O/R approach; please note: the name stands for Container Managed Persistence, not Database. The Entity Beans persistence approach is far from being optimal for O/R mapping, but it is the ONLY solution possible that allows persist data in different storage systems (DB, LDAP, file, ERP-system, mainframe), and to have relationships between them, and do transactions.

Yes, most applications need just DB persistence, and more optimal solutions are possible. Do I mean CMP must not be used? No, just beware the N+1 problem (it is not a problem but a feature), and do not be afraid of using plain SQL and JDBC to get lists of information about objects. Note: not objects (!), but information about them, and only if the user or system really wants to do CRUD upon an object, use Entity Beans.


EJBs in Production

Does anyone have any details of where they have used Enterprise Java Beans in production? Specific reasons for using them over plain vanilla servlets or non-Java platforms? Perhaps a list of Enterprise Java Beans Projects? see also: Ejb Case Studies


At IBM's Websphere2000 user conference held from March 26-29, 2000, in Miami, IBM trotted out a collection of Websphere customers to do the kiss-and-tell thing. I attended at least eight different sessions and reviewed the content for another four. None of the customers was using EJB, though Websphere has had this available since December 1998. Almost universally, these customers were using Websphere as a servlet and JSP host.

The audiences had the same questions you have right now, dear reader. Why? Why no EJB?

Remember, these customer presenters were hand-picked by IBM to describe their experiences with IBM software, particularly Websphere. The answers they gave fell into 2 categories: performance, and complexity. Some of the customers explained that they did perf evaluations of Websphere/EJB and found it wanting. One of them, a well-known online web-trading company who shall remain nameless, was quite clear and explicit about this; they continue to use FastCGI for HTML generation in favor of even Servlets or JSP, and CICS in favor of Websphere App Server.

OK. I was there too. There's no reason the customer should remain nameless since they clearly stated their name during the conference - Charles Schwab. I think you misunderstood the position - they are developing on BOTH CGI (they don't use fast CGI, by the way) and Servlets/JSP. They are even doing some EJB development. -- Anonymous Donor

[Just to address this, Schwab did describe their use of Servlets, for their Velocity application, which transmits data over the web, but is not their well-known dot-com site. Velocity uses a private address, transmits HTTP, but does not transmit HTML or XML, or anything a browser or internet presentation app might digest. It transmits a proprietary data stream between a fat client and a CICS server. The client is implemented as a Java application (not applet). The gateway just happens to be a single servlet program. The server is CICS/AIX. The Schwab rep made no other mention of JSP/Servlet, either in their schwab.com site or in the Velocity app, as far as I recall (and I was listening for this). As for doing EJB development, everyone seems to be doing EJB development. But deployments are hard to find. -- Dino Chiesa ]

Others explained that it wasn't clear to them how they should apply the EJB metaphor (entities vs sessions vs servlets). [See also, How To Use Entity Beans.]

At least one customer, another well-known financial services company, expressed plans to deploy an EJB-based app very soon. But none yet.

Full disclosure: I work for Microsoft. But you can verify this with any other attendee.

-- Dino Chiesa, 12 April 2000 (let the hate mail begin)


Actually, having also been at WebSphere2000, I distinctly recall several named customers (e.g. Greg Boettcher of Province of Manitoba customer talk), and unnamed customers (i.e. architectured discussed, best practices talked about, but industries, rather than customer names used with reference to EJBs -- for example, in both of Kyle Brown's sessions). Hence, I disagree that no production projects using EJBs were mentioned.

The point is not that development projects were not described; the point is that no one had deployed, not as of March 2000. No one seems to have any real experience running significant EJB-based systems.

[For clarity, the Province of Manitoba's first EJB (both Session and Entity beans) application went live on or about September 6th, 2000. -- Greg Boettcher]

Since asking the question that kicked off this discussion, I've been involved with two projects using EJBs -- one with a bank using EJBs as a generic service layer, variety of backend systems (CICS, IMS, etc.), the other for an online travel agent using Session Beans to wrap a travel booking backend, and Entity Beans for storage/retrieval of profile information. Perhaps there's a customer story or two in here for next time.

It would be very valuable to see these projects documented in Ejb Case Studies.


I've heard that many regard Entity Beans as the weak point of Web Sphere. Don't know if it's true, but even the rumor of it could explain why their customers avoid it.


I can't see as to why anyone would believe that. Our (Web Sphere's) CMP Entity support is basically unparalleled - we support things like Entity EJB relationships and Inheritance, which go significantly beyond the EJB 1.0 and 1.1 specs. The performance is also pretty impressive - very close to raw JDBC in some cases.


One theory could be that Web Sphere was one of the earliest implementations of EJB (?). At the time when EJB servers weren't as fast as they are now and few people knew how to create efficient applications with them all EJB servers probably got that reputation... -- Anders Bengtsson


IBM websphere's newsgroups have a very good active discussions on using ejb within there app server. ibm.software.websphere.application-server is the name.


Due to the debate over whether ejb's are a worthwhile technology, I would like to start a discussion on problems/scenarios where ejb's are a good solution or a particularly bad solution. I am kinda new to wiki, so I will attempt to create a page When To Use Ejb and hopefully get some input there. I have no idea how to add the page to the ejb category though.

-- skye

See original on c2.com