Although POJOs existed before, they play a more important role in the programming methodology of Java™ EE 5. Now, you can now create EJB applications with persistence capabilities by using enterprise beans and entities created from POJOs.
The complexity of the Java 2 Enterprise Edition framework used to present a major hurdle for adoption previously. The Java EE 5 specification sought a simpler development experience by making POJOs the basis of its design paradigm. The POJO programming model enables you to unit test outside of the application server, making the whole programming experience smoother.
The following code is an example of a simple POJO. Note that there are no references to any interfaces. To use this POJO as the basis for an EJB 2.1 application requires additional framework classes to support it and the class itself would have to implement additional interfaces.
public class Test { String name; /** * This is a constructor for a Test Object. **/ public Test(){ name = "Jane"; } }
To create an EJB 3.0 bean, inject a component defining annotation at the class level. The following example turns a POJO into a stateless session bean by adding the @Stateless annotation.
@Stateless String class Test { String name; /** * This is a constructor for a Test Object. **/ public Test () { name = "jane"; } }