As web applications become more serious, developers have become increasingly demanding about their tools. Over the last two months, we looked at two object-to-relational mapping tools (Alzabo and DODS) that make it possible to work with databases using object methods, avoiding the use of SQL inside of your program.
But there are a number of issues that many of these object-relational mapping tools fail to address: how can objects be separated onto different computers? Once separated, how can objects find each other? And if an object's state reflects the state of one or more database rows, how do we handle transactions?
These are messy and difficult questions, and we can expect to wrestle with them for years to come. One of the most comprehensive answers to these questions (and many others) is the J2EE (Java 2 Enterprise Edition) platform and its Enterprise JavaBeans object model. EJB, as it is known, is designed for use in complex, large-scale web sites and reduces the need for programmers to handle infrastructure issues.
This month, we will begin to look at EJB as implemented by the JBoss application server. JBoss is distributed under the GNU Lesser General Public License (LGPL), does not require much memory and is relatively easy to use. As is often the case with Java programming projects, working with EJB requires learning and working with a new set of tools, configuring several XML files in the right way and making sure that your CLASSPATH contains the right values during compilation and at runtime. If you can overcome these logistical hurdles, then JBoss provides an excellent basis for working with a powerful set of server-side technologies.
Before we continue, it's important to stress that neither EJB nor the Java language are truly free software. While you might not have to pay to download Java or the J2EE libraries, Sun owns everything having to do with Java, including the specifications. Sun's Community Source License is more open than many other licenses, but it is far from an open-source license.
This is particularly evident now that Lutris Corporation, who sponsored the open-source Enhydra application server, has pulled the plug on its J2EE-certified Enhydra Enterprise server. Lutris has turned Enhydra Enterprise into a closed-source project, claiming that Sun's license makes it impossible to deliver a fully compliant, open-source J2EE server. There has been a great deal of anger (and defensiveness) on the main Enhydra e-mail list, and many unanswered questions remain. Perhaps Lutris was legally (and financially) obligated to do what they did, but the manner in which they did it is an example of how not to close down an open-source project.
Luckily, the JBoss team has made it clear that JBoss will continue to be an open-source project, and that it will continue to grow and support all of the J2EE standards even if it lacks the official J2EE certification, largely because of the money required to receive such approval from Sun.
A good first question to ask is, “Why would I need EJB?” And indeed, there are many applications for which EJB is overkill. However, EJB provides functionality that would be difficult for us to implement on our own, inside of the server or container as it is known:
EJBs can reside on the same computer as your application, or on a remote computer. Thus, you can create multitiered applications in which each tier sits on a different computer, and your software continues to run unaltered as you move it from computer to computer or change the configuration of one or more tiers.
The EJB container can handle object-relational mapping issues for you. You define the database tables and the objects that map to them, and the container can handle the rest. Or if you prefer to fine-tune things yourself, you can let your bean manage its own persistence layer.
Relational databases provide transactions, allowing you to treat two or more operations as if they were a single operation. EJB gives your objects similar transactional capabilities, making it possible for a method to perform multiple actions as an all-or-nothing group.
It is also important to understand what EJB is not; despite the similar names, Enterprise JavaBeans have almost nothing to do with run-of-the-mill JavaBeans. JavaBeans have a standard API that allows us to access them from JSPs using little or no code. EJBs, by contrast, are designed to be used from any Java program, including servlets. Moreover, the standard API for EJBs is more rich, complex and flexible than that of JavaBeans. It's unfortunate that the term JavaBeans has been overloaded by these two popular server-side technologies, but there isn't anything we can do about it now.
One of the most compelling arguments for EJB is that the API is standard across application servers. Thus, you can begin working with an open-source EJB server such as JBoss, and then deploy on a commercial server when the time is ripe. (Although once you learn how much commercial servers cost, you may want to reconsider switching away from JBoss.)
Perhaps the most annoying part of working with Java is the great number of acronyms, project names and version numbers you must remember. This article works with the JDK (Java Development Kit) 1.3 and JBoss 2.4.1a server, which implements the EJB 1.1 standard. Moreover, while it is not particularly difficult to write the EJB classes themselves, the logistics associated with compiling and deploying them can be annoying and difficult for the uninitiated.
- Readers' Choice Awards 2013
- December 2013 Issue of Linux Journal: Readers' Choice
- IBM Will Minimize Impact of Future Disasters
- Raspberry Pi: the Perfect Home Server
- Sublime Text: One Editor to Rule Them All?
- Linux Systems Administrator
- RSS Feeds
- Technical Support Rep
- Senior Perl Developer
- Tech Tip: Really Simple HTTP Server with Python
- Reply to comment | Linux Journal
18 min 46 sec ago
- It's Jupiter
1 hour 18 min ago
- GIMP is certainly a graphic
2 hours 20 min ago
- Thanks For Your Sharing
7 hours 6 min ago
- Studying linux, and looking
10 hours 31 min ago
- voting for Best Linux Distribution
18 hours 58 min ago
- tizen vs android
23 hours 7 min ago
- i switch my choice from KDE
23 hours 34 min ago
1 day 2 hours ago
- Belanja Online
1 day 4 hours ago