aspose file tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB CMP/CMR Tutorial examples ported to JBoss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB CMP/CMR Tutorial examples ported to JBoss" Watch "EJB CMP/CMR Tutorial examples ported to JBoss" New topic

EJB CMP/CMR Tutorial examples ported to JBoss

Rick Hightower
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
Peter from WestSideWidgets was kind enough to port the examples to JBoss. I used XDoclet to generate the deployment descriptors, but never spent the time with JBoss to test them. Peter tested them and fixed them. Thus, the example has been ported to JBoss.
(Part 1 and 2 worked with RI. Part 3 and 4 worked with WebLogic.)

JBoss Port!
If you don't know what I am talking about see....
EJB CMP/CMR Tutorial
But here is a hint....
This tutorial is designed to introduce you to Container-Managed Persistence (CMP) and Container-Managed Relationships (CMR) in Enterprise JavaBeans 2.0 (EJB). (Source code for examples at bottom of page)
About the code:
The code in the first two parts works with Sun's RI for J2EE. Peter Luellen from West Side Widgets created the deployment descriptors to get final code from part 1 and 2 working for JBoss. Peter also got the examples for part 3 and 4 to work with JBoss. Please check out the JBoss Port of the examples.
The code for part 3 and 4 was tested with BEA WebLogic, but should work with other application servers as well. The code from part 3 and 4 was based on the code from part 2. I modified the code to use EJBDoclet task (part of XDoclet). XDoclet ROCKs! The ant build script is set up to run EJBDoclet task. I suggest you check out XDoclet... it is the bee's knees! (Peter Luellen tested and fixed the code so that it would also work with JBoss.)
A future article will show how to port the code to many different application servers.

Rick Hightower is CTO of Mammatus which focuses on Cloud Computing, EC2, etc. Rick is invovled in Java CDI and Java EE as well. linkedin,twitter,blog
Rick Hightower
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
here is peter message about the JBoss port:


I've deployed and tested all the code for parts 1-4 of the tutorial. There were a couple of changes I had to make in order to get it to work on JBoss. The changes are detailed in the attached changes.txt. (show on this page RMH)

The changes mostly stem from JBoss's approach to creating tables. It seems that JBoss wants to treat each cmr field as an additional table column when it generates SQL to create tables. (That's why I got an SQLException before I changed the UserInfoContainedByUser relationship role column name from EMAIL to FK_USER_INFO).

I also finished the simple jsp testing gui (.war file attached). To make life easier in coding the gui, I used the Delegate pattern and created a UserManagementDelegate (source code attached) that creates a reference to a remote UserManagement session bean and passes calls to it onto the session bean.

Let me know what you think. (I think you ROCK! RMH)

Rick Hightower
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
There was only six small changes....

Here's a list of the things I did to deploy the tutorials on JBoss 3.0.1
Problem 0) Primary key cmp fields were listed twice for each entity in jbosscmp-jdbc.xml.
Fix: Removed duplicate entries.

Problem 1) 2002-08-14 13:35:56,609 ERROR [org.jboss.ejb.EjbModule] Initialization failed
org.jboss.deployment.DeploymentException: CMP field for key not found: field name=NAME

Fix: Edited jbosscmp-jdbc.xml file. The <ejb-relationship-role>.<key field>.<field-name>
attributes in this file were in uppercase and didn't match case with the field names in
the ejb-jar.xml file.
For example this:

was changed to this:


Problem 2) 2002-08-14 13:47:10,227 ERROR [org.jboss.ejb.EjbModule] Initialization failed
org.jboss.deployment.DeploymentException: Role: UserInAGroup with multiplicity many
using foreign-key mapping is not allowed to have key-fields
Fix: Edited jbosscmp-jdbc.xml file. Removed the UserInAGroup key fields.

Problem 3) 2002-08-14 14:55:08,852 ERROR [org.jboss.ejb.EjbModule] Starting failed
org.jboss.deployment.DeploymentException: Error while creating table; - nested throwable:
(java.sql.SQLException: Invalid argument value: Duplicate column name 'EMAIL')
Fix: Edited jbosscmp-jdbc.xml file. Changed the UserInfoContainedByUser
relationship role column name from EMAIL to FK_USER_INFO.
Added a column (FK_USER_INFO) to TBL_USER:
create table TBL_USER (
EMAIL varchar (100) primary key,
PASSWORD varchar (25),
FK_GROUP_NAME varchar (25),
FK_USER_INFO varchar (100),
Changed the constraint on TBL_USER_INFO to reference column added above:
create table TBL_USER_INFO(

Problem 4) 2002-08-15 02:46:53,706 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.
User.findLastNameLike] EJB-QL: SELECT DISTINCT OBJECT(user) FROM User user WHERE
user.userInfo.lastName LIKE ?1
2002-08-15 02:46:53,716 WARN [org.jboss.system.ServiceController] Problem starting
service jboss.j2ee:service=EJB,jndiName=User
org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable:
(org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "1" at line 1, column 79.
Was expecting:
Fix: Edited ejb-jar.xml file. Changed "LIKE" to "=". JBoss 3.0.1 does not support
EJB-QL "LIKE" expressions with input parameters.

Problem 5) No table specified for UserAssociatedWithRoles relation.
Fix: Added <relation-table-mapping> to jbosscmp-jdbc.xml ejb-relation

Problem 6) TBL_USER.FK_USER_INFO column was not set when adding full user
(user with info), and user.userInfo was not navigable.
Fix: Edited UserMamagementBean.addUser method by adding a call to
UserLocal.setUserInfo(UserInfoLocal info):
public void addUser(String email, String password, String firstName, String middleName, String lastName,
String dept, String workPhone, String extention, String homePhone,
boolean isEmployee, String groupName){
try {
UserLocal user = userHome.create(email, password);

//Associate userInfo to group
UserInfoLocal info = infoHome.create(firstName, middleName, lastName,
email, dept, workPhone, extention, homePhone, isEmployee);
//Pete added this call

//Add user to group
GroupLocal group = groupHome.findByGroupName(groupName);

} catch (CreateException e) {
throw new EJBException
("Unable to create the local user " + email, e);
} catch (FinderException e) {
throw new EJBException
("Unable to add user to the group " + groupName, e);


Rick Hightower
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
Please check out the tutorial....
It is a good way to get started with EJB.
It is a good way to get started with EJB CMP/CMR and EJB QL.
What people think:

Achim from Germany writes: "I read your white papers "Introducing EJB-CMP/CMR" part 1 and part 2.... These papers are the best start for EJB.... Now I'm very interested in part 3 (and 4), but I can't find them on the developerWorks Homepage ..." (They are out and ported to JBoss and WebLogic.)
Pete from North Carolina writes: "I've been working through your "Introducing EJB-CMP/CMR" tutorials. Great stuff. Well presented - simple and straight forward. Really learning a lot. "
Patrick from the U.S.A. writes: "Great Job on part 1 and 2 of your tutorial on CMP/CMR and EJB QL. When will part 3 and 4 be out.? Will it be able to run on JBoss Resin, and Orion." (It is done! Part 3 and 4 works with WebLogic and JBoss. I got the examples working with WebLogic and Peter got them working with JBoss. --Rick)
Chintan writes “...thank you for putting out fabulous quality CMP/CMR tutorial. This is the best tutorial I have ever seen. Complete, concise and clear. (Where is the source?) (The source code is at the bottom of this page.)”
Rick Hightower
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
Complete zip file with build script for JBoss for part 1 and part 2 (contributed)
Yin just contributed a zip file for part 1 and 2.
Sounds like it will simplyfy development for jBoss developers.
He modified the build and such....
jboss updates for tutorial

Hi Pete and Rick,
I just thought that I might make a small contribution by sending you the jboss port of the part 1-2 series of Rick's cmp/cmr tutorial
series. I couldn't find it on pete's website (I might have missed them... , I saw the part 3-4 port though ). Pete, if you don't have them on
your website, you can post them for all these guys who are just starting out ....
I customized the script for the client , run.bat to run for jboss and also customized the
build.xml, added a jboss.xml and jbosscmp-jdbc.xml
file in the session and entity descriptor folders.

I also use the build in db of jboss, hypersonic sql and added trace output for all the methods that can be followed on the jboss console.

Everything seems to work fine on my computer. Let me know if it works for you too.

Thanks Rick for the great tutorial !!!
(Sure... no problem --Rick )



Thanks Yin!
I agree. Here's the link:
subject: EJB CMP/CMR Tutorial examples ported to JBoss