EJB 3(1) - So, How Portable Is Actually This Stuff In The Practice?
The EJB 2 spec was just too simple - this was the real problem :-). Because EJB 2 were underspecified, vendors were especially creative in proprietary extensions. The result was a relative "simple" ejb-jar.xml and often several, huge, proprietary, vendor specific deployment descriptors. Porting an application from one appserver to another was almost mission impossible. You had to map those vendor-specific extensions first.
Although EJB 3 is considered as simple, the spec standardizes lot more features, than it was the case in EJB 2. There is almost no room for vendor-specific extensions. At least, I never used any vendor extensions in my EJB 3 projects. In addition XML was entirely eliminated. You could specify whatever you want in XML, but you don't have to. What you get a are few annotated POJOs, without any additional configuration - so what can go wrong here?. I neven encountered any problems porting the applications between JBoss 4.X, Glassfish v1, v2, Weblogic 10 and even Websphere 6.1. What I ran to several times, however, were bugs, especially in the area of commercial application servers (which is actually funny). I encountered the following problems, lots of them are already fixed:
- Injection of Session Beans into Backing Beans, or injection between web container and EJB container in general (1.5 years ago - problem is already fixed)
- Injection of Session Beans into Interceptors (one commercial app server).
- Limitations of some JPA-providers, especially autoincrement, lazy loading behavior, polymorphic relations.
- Synchronization issues of complex, attached graphs of persistent objects
In EJB 3, however, there is a real issue with JNDI naming, which was fixed in EJB 3.1. Every application server uses its own JNDI-naming scheme. It is only a problem, if you are accessing remote beans via CORBA or RMI directly. Most application servers have reasonable and consistent naming patterns - like fully qualified remote interface names, so this problem can be very easily fixed with a ServiceLocator. Its actually the only problem with the spec regarding portability. A potential danger is the "mappedBy" attribute, which is not clearly defined by the spec. In the practice most application servers map it directly to JNDI.
Dependency Injection inside the container will work as expected - you do not have to configure anything in the default case because of Convention Over Configuration...
Classloading could be an issue if you are deploying many frameworks and libraries. It could become especially funny with AOP frameworks, which often rely on classloader tricks to be able to weave the classes at load time. In my projects I tried to reduce the amount of libraries and leverage existing JDK 1.6 stuff instead. So I never ran into classloading issues except come classic ones like Log4J or SLF4J. Funny enough the last time I had this problem with a plain WAR :-). Ironically: the heaviest classloading problems ever I encountered during Eclipse RCP development trying to properly integrate Hibernate and Log4J as plugin without Buddy-Classloading hack. ...Eclipse RCP is based on OSGI :-).
The problems were easily solved in few hours (if not minutes). In some projects we deployed the same EJB-JAR into different application servers in parallel (simple ANT-copy) - and ran the unit tests against different providers...
Security is pretty good standardized as well - with JACC. But even without this standard most application servers have similar, RBAC based security concepts. They (e.g. Glassfish, JBoss) support file, database and LDAP realms out-of-the-box.
EJB 3 is a multi-vendor abstraction, so it is leaky per nature. You shouldn't expect any miracles - but the portability of EJB 3 is comparable with the portability of a WAR. JPA is a bigger problem, because there are more qualitative differences between provider and their support of database proprietary features in particular. The real portability issue in the practice are not EJBs but the non-functional differences between different application servers (scalability, performance, administration etc.).
Actually from strategic point of view, EJB 3 are really interesting for product development - you are really independent of particular infrastructure provider.... There are even several, competing opensource EJB 3 containers available...(Glassfish, JBoss, Geronimo).
what about Resource-Injection?
Did you recognize any problems with different resources (e.g. JCA) on different EJB-containers / Appservers?
Posted by Robert on January 23, 2009 at 01:09 PM CET #
I used @Resource(mappedBy) on GF v1, v2, JBoss 4.X and WLS 10 for injection of DataSource and Destinations (and other JMS infrastructure), without any issues. The code was just portable.
JCA connectors worked well even back in the J2EE days. I use JRA (SAP name for JCA) from SAP, it was deployable on JBoss, SAP (:-)) without pain. It was too early for GF these days.
In Java EE 5 I built a connector for Glassfish and deployed several as well - no issues so far.
thanks for your comment,
Posted by Adam Bien on January 24, 2009 at 10:32 AM CET #
thanks for your answer. This will help me much more to advice Java EE for my current project.
We're a little afraid about the compatibility of JCA connector's between several AS.
Posted by Robert on January 26, 2009 at 11:58 AM CET #
my experience with JCA was surprisingly good. But you should test the actual behavior and not just rely on the spec. But this is even true for porting a webapp from jetty to tomcat :-),
Posted by Adam Bien on January 26, 2009 at 12:14 PM CET #