Simplify persistence container management
The CMP entity bean will become EJB3.0 to enable developers to enforce a major inspection method. Persistence frames such as Oracleas Toplink, open source Hibernate have become unlike the complex and heavyweight development J2EE persistent framework applications like entity Beans. EJB3.0 adopts Toplink and Hibernate lightweight persistent mode to simplify container persistence management, which sounds more happy. Let us browse the entities of the entity bean, we will discuss details of persistent improvements in another article.
The entity bean has been changed to the POJOS, and the entity bean will not need the component interface. Entity Beans now look into a pure object that supports inheritance and polymorphism.
The following is about the entity bean source code
@ENTINTITY PUBLIC CLASS EMPLOYEE {
PRIVATE Long Empno;
PRIVATE STRING Empname;
Private address address;
Private hashmap projects = new hashmap ();
PRIVATE DOUBLE SALY;
@ID (generate = sequence) public long positionEmpno () {
RETURN EMPNO;
}
Protected void setempno (long Empno) {
THIS.EMPNO = Empno;
}
Public string geTempname () {
Return Empname;
}
Public void setempname (String Empname) {
this.empname = Empname;
}
@Dependent public address getaddress () {
Return Address;
}
Public void setaddress (address address) {
THIS.ADDRESS = Address;
}
Public set getProjects () {
Return Projects;
}
Public void setProjects (set projects) {
THIS.PROJECTS = Projects;
}
Public Double getSalary () {
Return Salary;
}
Public void setsalary (double salary) {
THIS.SALARY = SALARY;
}
....
}
If you look at these code carefully, you can find that the Bean class in the current entity bean is a specific class and no longer an abstract class.
EJB QL and entity beans have made multiple improvements. A new entity management of Hibernate management API and Simplified version of Toplink's session API is recommended to handle the operation of entity beans, that is, the creation, release, and lookup of entity beans.
We will further make more verification on the details of the suggestion of the CMP entity bean in an in-depth article.
Simplify EJB client
Even if EJB is serialized, it is also very complicated using EJB to find and call. J2EE 1.4 and EJB 3.0 Specifications are committed to simplifying the EJB client.
If you want to use EJB you must define an EJB reference or EJB local reference in the deployment description, find the EJB and then call it. If we want to call HelloWorld's EJB, you can call EJB to use existing implementations as follows.
Find the definition of EJB indication in the deployment description
EJB-REF>
Then look for EJBs as follows. You need to express the exception when ejb lookup and establish a bean instance.
Try
{
Context context = new initialContext ();
HelloWorldHome HelloHome =
(HelloWorld) PortableRemoteObject.narrow (Context.lookup
("Java: Comp / Env / EJB / HelloWorldejb"), HelloWorldHome.Class;
HelloWorld Hello = HelloHome.create ();
....
}
Catch (RemoteException E)
{
System.err.println ("System / Communication Error:" E.GetMessage ());
}
Catch (Namingexception E)
{
System.err.println ("Communication Error:" E.getMessage ());
}
CATCH (CREATEXCEPTION E)
{
System.err.Println ("Error Creating EJB Instance:" E.GetMessage ());
}
As a change in environment variables, EJB3.0 recommends finding and calling EJBs using methods of placing inJection.
Below we use the method of placing the inJection in another EJB to find HelloWorldejb.
@INJECT Private Void SetSessionContext (sessionContext CTX)
{
this.ctx = CTX
}
...
MyHello = (HelloWorld) CTX.lookup ("Java: Comp / ENV / EJB / HelloWorldejb");
If you look carefully to the code above, its dependent INJECTION uses @ITSet to specify the Annotations for the sessionContext method. The INJECTION method will be able to call the EJBCONText before the business method is called before being called by the EJB.
Another direct example of another injected HelloWorld session bean can be simplified to use
@Ejb public helloworld myhello, which will make Myhello by the HelloWorld Bean instance injected.
You can use the dependent INJection to query any type of environment and resource references such as DataSource, JMS, Mail, Web Service, and more.
Container external test feasibility
An EJB developer is not only the complexity of EJB development, but also the terrible of testing. Development and test EJBs must require an EJB container and developers must be familiar with the final deployment platform to perform tests. This is a big problem for many business developers who are developing only a major platform, but is a big problem for the support of multiple developer platforms and to test EJB ISVs in maintenance. The EJB3.0 specification promise will provide the function of the container test, but this is lost in this specification.
in conclusion
Although there are still many details about packaging, assembly and important API details, there is no mention of this norm, but many recommendations make EJB3.0 specifications to make enterprise Java developers look forward to their future. Through these undoubtedly, it will help reduce development complex from developers to service providers. Here's how to see how service providers are implemented, and make EJB3.0 a leader of enterprise application. Author Bio Author
Debu Panda is the main manager of the Oracle Application Services Development Team, and he has achieved many achievements in EJB containers and transaction management. He has 13 years of experience in IT industry and has published a lot of works in a number of magazines and technology publishers.
Translation problem:
Since some English nouns have not dared to translate, the original word in English is in the text.
Cleaning Up The Dirty Laundry Squiring Defect
Low Carb
Atkins Diet
Metadata annotations metadata description
Simplifying Client View for EJBS Simplifies EJB Clients
Dependency Injection Dependency INJECTION
Setter Injection Ontal Injection
ISV Independent Software Vendor Independent Software Supplier