This series of articles I published in IBM website according to Rick Hightower
"
EJB - CMP / CMR Introduction "Adapted, this is a series, with 4 articles. This article integrates the four articles, see this article, you must refer to it, so it is very convenient, but I have made some modifications, the principle is basically still constant. I don't say knowledge about CMP, I just introduce how to develop CMPs in Eclipse using Lomboz and JBoss-IDE.
This article mainly tells how to develop multi-to-many one-way contacts, which is designed here, and UserBean is designed to control the rolebean by UserBean. The focus is on how to build multiple one-way contacts using XDoclets, and the client call is relatively simple.
This article is ""
Eclipse quickly picks EJB - 2. Design an entity bean ","
Eclipse quickly applied EJB - 3. Design a pair of CMR (1) "extends. Therefore, there must be the foundation of these two articles.
Regarding the environmental configuration, use skills to refer to my previous article, here as much as possible.
First, design entity bean: rolebean
1. Establish a main part:
●
In the CMP_SAMPLE project, right click "SRC" -> New -> Lomboz EJB CREATION WIZARD:
· Package (K): javamxj.ejb.cmp
· Name (M): Role
· EJB TYPE: Select Container Managed Entity EJB
Click Next.
● Schema Name: Roleschema
Table name: Roletable
● Add a NAME column:
· Field: Name
· Field Type: java.lang.string
· Database column: Permissions Name
· SQL TYPE: VARCHAR
And make it a primary key.
● Similarly, add a DESCRIPTION column:
· Field: Description
· Field Type: java.lang.string
· Database column: permission description
· SQL TYPE: VARCHAR
The effect is as follows, and finally click to complete.
Note: As the above article, the SQL-Type = "varchar" in the generated code is changed to SQL-TYPE = "VARCHAR (XY)", XY is a suitable varchar bit number.
2.
Complete EJBCREATE and EJBPOSTCREATE methods:
3. Add the following tags to the class tag:
●
The complete source code for RoleBean.java is given below:
Rolebean.java
/ * * Create date 2005-1-25 * * Author:; javamxj (share the joy of java) * / package javamxj.ejb.cmp / ** * * You can insert your Documentation for ' Rolebean b> em>'. * XML Version = "1.0" encoding = "UTF-8"?>
} / ** * The container invokes this method immediately after it calls ejbCreate. * / Public void ejbPostCreate (String name, String description) throws javax.ejb.CreateException {} / ** * CMP Field name * @return the name * @ Ejb.Persistent-Field * @ ejb.persistence * Column-name = "Permissions Name" * JDBC-TYPE = "VARCHAR" * SQL-TYPE = "VARCHAR (12)" * read-only = "false" * @EJB. PK-Field * * @ ejb.interface-method * / public abstract java.lang.string getName (); / ** * @Param java.lang.string the new name value * @ ejb.interface-method * / public abstract Void setname (java.lang.string name); / ** * CMP Field Description * @return the description * @ Ejb.Persistent-Field * @ Ejb.Persistence * Column-name = "Permission Description" * JDBC-TYPE = " VARCHAR "* SQL-TYPE =" VARCHAR (30) "* read-only =" false "* * * @ ejb.interface-method * / public abstract java.lang.string getdescription (); / ** * @Param Java .lang.str @ ejb.interface-method * / public abstract void setdescription (java.lang.string description);} Ok, save, add RoleBean to the CMPEJB module, then lomboz -> generate ejb classes.
4. Focus: Establish Userbean's multiple-to-many one-way contacts for Rolebean:
·
Since this design is UserBean's one-way link to RoleBean, you only need to add method tags to the UserBean.
Switch to UserBean.java, right-click Userbean -> J2EE -> Add CMR Relationship:
·
The generated tag is as follows, but also needs to add some @Jboss tags:
·
Save, Generate EJB CLASSES