Adam Bien's Weblog

EJB 3.0 and "Legacy" POJOs - deploying Swing's TableModel as Session Bean

Some of the reactions to my post "Are Plain Old WebContainers still appropriate in Java EE 5?" implied, that it could be hard to integrate "legacy" POJOs with plain EJB 3 technology. To clarify this issue, I tried to deploy a really "legacy" POJO as a Stateless / Stateful Session Bean. ...I tried to deploy an already existing class - the javax.swing.table.DefaultTableModel as a Session Bean (!!!), without changing the source code. The deployment (to Glassfish v2), as well as test worked (!!!). It's interesting, but many developers think, that EJB 3 can only works with annotation - or bloated deployment descriptors...

To clarify this point, I declared the DefaultTableModel as a Stateless Session Bean with the following Deployment Descriptor:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns = ""
         version = "3.0"
         xmlns:xsi = ""
         xsi:schemaLocation = "">

The  ejb-jar archive is empty in this case - it only contains the deployment descriptor. However the declaration of this legacy POJO in xml allows it injection to an "usual", annotated session bean:

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebService;
import javax.swing.table.TableModel;

public class LegacyTestBean implements LegacyTest {
    private TableModel tableModel;

    public String accessTable(){
        return "Row count: " + tableModel.getRowCount();

The attribute "beanName" of the @EJB annotation refers to the name of the declared bean. As you can see, with just few lines of XML code it is possible to deploy almost every class as a session bean. The requirements are only:

  • The existence of the default constructor
  • The business interface is required

EJB 3 are really interesting - even for very small and trivial projects. I checked in the whole project into p4j5. The projects name is "LegacyPojo" - it was tested with Glassfish V2 and Netbeans 6b1.

[See also page 37 in the "Real World Java EE Patterns - Rethinking Best Practices" book]

NEW workshop: Building HTML 5 Applications With React.js
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7, Java EE 7 Testing and NEW: Java EE 7 Microservices are available for streaming


A book about rethinking Java EE Patterns


Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments