Introduction it is expected that the first draft of EJB3.0 has been released recently. In this article, we will give an overview of the new specifications, including new metadata support, modifications to EJBQL, and new methods and runtime environments for accessing Bean context using the Entity bean model. The author also discussed the future adjustments of EJB and the relationship between EJB3.0 and other development specifications. Start EJB
Introduction
The long-awaited EJB3.0 specification has recently released its first draft. In this article, we will give an overview of the new specifications, including new metadata support, modifications to EJBQL, and new methods and runtime environments for accessing Bean context using the Entity bean model. The author also discussed the future adjustments of EJB and the relationship between EJB3.0 and other development specifications.
Start
In any case, due to the complexity of EJB, the performance in The J2EE architecture has never been very good. EJB is probably the only one in the J2EE architecture that does not realize its ability to develop and improve productivity. The EJB3.0 specification is trying to reduce the complexity of its development in this regard. EJB3.0 reduces the workload of developers for underlying development. it cancels or minimizes the implementation of many (which were previously required) callback methods, it also reduces the complexity of the Entity Bean and the O/R ING model.
In this article, I will first introduce several major changes in EJB3.0. It is very important to have a deep understanding of EJB3.0. Later, I will describe the details that have been submitted to the EJB3.0 specification from a higher level, and explain the changes in the new specification one by one: Entity Bean, O/R ING model, entity-link model and ejb ql (EJB Query Language.
Background
Two important changes in EJB3.0 are the use of the program annotation tool in Java 5 and the O/R ING model based on Hibernate.
Metadata tools in Java 5
Java 5 (formerly J2SE1.5 or Tiger) adds a new program annotation tool. With this tool, you can customize annotation tags to annotate fields, methods, classes, and so on. These annotations do not affect the semantics of the program, but they can be interpreted using tools (at compilation or runtime) and additional content (such as deployment description files ), or force certain required runtime behaviors (such as the status characteristics of the EJB component ). Annotation parsing can be performed through source file parsing (such as the compiler or this IDE tool) or using the APIs reflection mechanism in Java 5. Annotations can only be defined at the source code layer. Because all annotation tags submitted to the EJB3.0 draft have a runtime RetentionPolicy, this will increase the storage space occupied by class files, however, this makes it easier for container manufacturers and tool manufacturers.
Hibernate
Currently, Hibernate is very popular. it is a Java O/R ing framework for source code development. it aims to free developers from tedious data persistence programming. It also has a standard HQL (Hibernate Query Language) language, which you can see in the new ejb ql. Hibernate is very simple in terms of data query, update, connection pool, transaction processing, and entity link processing.
Overview
The submitted EJB3.0 specification involves two major changes:
1. a set of annotation-based EJB programming models, coupled with the application behavior defined in EJB2.1 through the deployment descriptor and several interfaces.
2. the new object Bean persistence model and EJBQL also have many important changes.
There are also some proposals, such as a new client programming model, the use of business interfaces, and the lifecycle of entity beans. Note that the EJB2.1 programming model (including the deployment descriptor and home/remote interface) is still valid. The new simplified model does not completely replace EJB2.1.
EJB comment
An important goal of the EJB specification organization is to reduce the number of original code, and they provide a perfect way to introduce it. In EJB3.0, any type of enterprise-level Bean is a simple Java object (POJO) that has been properly annotated ). Annotations can be used to define the business interface, O/R ing information, and resource reference information of beans. The effect is the same as that of the deployment descriptor and interface defined in EJB2.1. Deploy descriptors in EJB3.0 is no longer necessary; the home interface is no longer required, and you do not need to implement business interfaces (containers can do these tasks for you ).
For example, you can use the @ Stateless annotation tag class to declare a Java class as a Stateless session bean. For stateful session beans, the @ Remove annotation can be used to mark a specific method. through this annotation, the bean instance will be cleared after the method is called.
To reduce the description of the component, the organization also adopted the configuration-by-exception method, this means that you can provide a clear default value for all comments so that most common information can be inferred accordingly.
New persistence model
The new entity bean is also a simple Java Object (POJO) with annotations added ). Once accessed by EntityManager, it becomes a persistent object and a part of the persistent context. A persistent context is loosely coupled with a transaction context. Strictly speaking, it implies coexistence with a transaction session.
Entity relationships are also defined through annotations, and O/R ING is also required, and several different database standard operations are provided, in EJB2.1, this is done through the developer's own design patterns or other technologies (for example, self-increasing primary key policies ).
In-depth research
Now it is time to learn more about the EJB3.0 draft. Let's start to explore four enterprise-level beans in all EJBs and see what they look like in the new specifications.
Stateless session bean
In the EJB3.0 specification, writing a Stateless session bean (SLSB) only requires a simple Java file and adds @ Stateless annotation to the class layer. This bean can extend the javax. ejb. SessionBean interface, but these are not necessary.
An SLSB no longer needs the home interface, and no EJB needs it. Bean class can implement business interfaces or not. If no business interface is implemented, the business interface is generated by any public method. If only a few business methods are exposed to the business interface, you can use the @ BusinessMethod annotation for these methods. By default, all the interfaces generated are local interfaces. you can also use the @ Remote annotation to declare this interface as a remote interface.
The following code defines a HelloWorldbean. In EJB2.1, the same bean requires at least two interfaces, one implementation class and several empty implementation methods, and the deployment descriptor.
Import javax. ejb .*;
/**
* A stateless session bean requesting that a remote business
* Interface be generated for it.
*/
@ Stateless
@ Remote
Public class HelloWorldBean {
Public String sayHello (){
Return "Hello World !!! ";
}
}
Stateful session bean
In addition to some special descriptions of SFSB, stateful session bean (SFSB) is as streamlined as SLSB:
An SFSB should have a method to initialize itself (in EJB2.1, it is implemented through ejbCreate ). In the EJB3.0 specification, we recommend that you use custom methods to perform initialization and expose them to business interfaces. Before using this bean, the client calls the corresponding initialization method. Currently, it is still controversial whether the organization provides a comment to mark a method for initialization.
The Bean provider can mark any SFSB method with the @ Remove annotation to indicate that the bean instance will be removed after this method is called. Similarly, the organization is still discussing whether there is a mechanism to handle this special situation, that is, whether the bean instance is removed when this method encounters an exception.
My personal views on the above issues are as follows:
1) Should there be a comment indicating a method for initialization? My opinion is: