Eclipse quickly picks EJB - 3. Design a one-to-one two-way relationship CMR (1)

xiaoxiao2021-03-06  24

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 a one-to-one two-way relationship, which is designed with a UserInfobean, and the article.

Eclipse Quick Purchase EJB - 2. Designing the UserBean in an entity bean establishes relationship, which is also from which it will continue to extend. Therefore, there must be the foundation of the previous article.

Regarding the environmental configuration, use skills to refer to my previous article, here as much as possible.

The complete source code has been attached.

I. Design entity bean: Userinfobean

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): UserInfo

· EJB TYPE: Select Container Managed Entity EJB

Click Next.

● Schema name: userinfoschema

Table Name: Userinfotable

● Add an email column:

· Field: email

· Field Type: java.lang.string

· Database column: Email

· SQL TYPE: VARCHAR

And make it a primary key.

● Similarly, add another Name column:

· Field: Name

· Field Type: java.lang.string

· Database colorn: Name

· SQL TYPE: VARCHAR

● Similarly, add a DEPT column:

· Field: DEPT

· Field Type: java.lang.string

· Database column: Group

· SQL TYPE: VARCHAR

● Similarly, add a Workphone column:

Field: Workphone

· Field Type: java.lang.string

· Database column: Workload

· SQL TYPE: VARCHAR

● Similarly, add an AGE column:

· Field: AGE

· Field Type: java.lang.integer

· Database colorn: age

· SQL TYPE: INTEGER

● Similarly, add a SALARY bar:

· Field: Salary

· Field Type: java.lang.integer

· Database column: salary

· SQL TYPE: INTEGER

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.

4. EJB.SELECT method

· Right-click UserInfobean -> J2EE -> Add SELECT METHOD (JBoss-Ide: If you don't know how to call out, look at the article)

·

Since the ejb.select method needs to be indirectly used through the home interface,

Right click UserInfobean -> J2EE -> Add Home Method

· As shown in the figure, click "Finish" to generate the code, you need to manually add a return statement.

5. Add UserInfobean to the CMPEJB module, then lomboz -> Generate EJB CLASSES

As shown below, 6 files are generated, where userinfovalue.java is the "@ Ejb.Value-Object" tag generated value object.

6. Add an abstract method to call the value object.

7. Key: Establish a one-to-one two-way relationship with UserInfobean and Userbean:

· Right click UserInfobean -> J2EE -> Add CMR Relationship:

·

After clicking "Finish", generate the following code (the statement in the red box requires manual addition):

·

Switch to UserBean.java:

Right-click Userbean -> J2EE -> Add CMR Relationship:

·

After clicking "Finish", generate the following code (the statement in the red box requires manual addition):

OK, again generate ejb classes, if everything is normal, proceed to the next step.

(You can look at the code generated in ejb-jar.xml and jbosscmp-jdbc.xml files). Eclipse Quick EJB - 3. One-to-one two-way relationship CMR (2) Eclipse Quick Pickup EJB - 3. One-to-one two-way relationship CMR (3)

转载请注明原文地址:https://www.9cbs.com/read-65096.html

New Post(0)