Thursday, September 26, 2002


Pere Torrodellas had a question about Identity keys, WebLogic and EJB CMP CMR as follows:

"I'm trying to develop a CMP bean on a DB table that has a column defined as "auto increment", i.e. I don't set any value for this attribute in ejbCreate() and the DB manager sets it when the row is inserted.

In order to get the value assigned to the column in the same client method that created it, I invoke a finder that retrieves the just created Bean by looking for another column value.

To my dismay, the contents of the "auto increment" attribute is still null, which suggests that either the container has not yet performed the insert in the DB, or it performs a first search in its storage instead of accessing the persistent media.

How can I force the container to immediately store the bean in the DB and refresh its data to get the automatically generated value? I suppose I could do it with a BMP (right?), but I'd rather use a CMP if possible."

Here is my response


I read your question, and the first thing that popped in my mind was which app server are you using....

The app server you are you using can really impact how to handle auto increment ids. I hope they fix this part of the spec. up before EJB 2.2. Some EJB containers handle auto Ids transparently (e.g. Resin EE). Some EJB containers do no handle them at all. And, Some App servers require special mojo in the configuration files...

I saw that you stated you are using WebLogic 6.1.

WebLogic 6.1 uses the special mojo configuration file approach. (Hey can I identify that as a pattern... the special mojo pattern.... probably not)

In your cmp mapping file (weblogic-cmp-rdbms-jar.xml)

You will need to add one of these
<automatic-key-generation>
<generator-type>NAMED_SEQUENCE_TABLE</generator-type>
<generator-name>CUSTOMER_SEQUENCE_TABLE</generator-name>
<key-cache-size>10</key-cache-size>
</automatic-key-generation>


There are several generator types depending on what database you are using. For example there is one specific to Oracle, and one Specific to MS SQL Server. I don't know why they don't have one specific to the IDENTIY keyword which is standard SQL 92 but they don't.

MS SQL Server uses the IDENTIY keyword, Oracle 8 does not, but most other RDBMS servers do (DB2, MYSQL, Access, HyperSonic SQL, Cloudscape and so on) so you can try this approach with non MS SQL Server.

If possible use the NAMED_SEQUENCE_TABLE for the generator.... it is the most portable. This is a hard sell if you are in an Oracle shop and you using Sequences in that case use the Oracle Sequence option. Refer to the weblogic docs for more information on <generator-type>s.


Here is what the DDL would look like for the NAMED_SEQUENCE_TABLE approach for a simple Customer EJB.


-- customer
-- customer has many orders
create table TBL_CUSTOMER (
CUSTOMER_ID INT primary key,
FIRST_NAME varchar (25),
LAST_NAME varchar (25),
EMAIL varchar (100),
PHONE varchar (25)
);

create table CUSTOMER_SEQUENCE_TABLE(SEQUENCE integer);
insert into CUSTOMER_SEQUENCE_TABLE values (100);

Here is the rest of the mappings for this example to put it all into context....


<weblogic-rdbms-bean>
<ejb-name>Customer</ejb-name>

<data-source-name>mysource</data-source-name>

<table-name>TBL_CUSTOMER</table-name>

<!-- Study these mappings from the TBL_CUSTOMER columns to the Customer EJB cmp fields -->

<field-map>
<cmp-field>iD</cmp-field>
<dbms-column>CUSTOMER_ID</dbms-column>
</field-map>
<field-map>
<cmp-field>firstName</cmp-field>
<dbms-column>FIRST_NAME</dbms-column>
</field-map>
<field-map>
<cmp-field>lastName</cmp-field>
<dbms-column>LAST_NAME</dbms-column>
</field-map>
<field-map>
<cmp-field>phone</cmp-field>
<dbms-column>PHONE</dbms-column>
</field-map>
<field-map>
<cmp-field>email</cmp-field>
<dbms-column>EMAIL</dbms-column>
</field-map>

<!-- TODO study this finder method -->


<weblogic-query>
<query-method>
<method-name>findByEmail</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<weblogic-ql>SELECT DISTINCT OBJECT(c) FROM Customer c where c.email = ?1</weblogic-ql>
</weblogic-query>


<!-- TODO study this auto key generator -->




<automatic-key-generation>
<generator-type>NAMED_SEQUENCE_TABLE</generator-type>
<generator-name>CUSTOMER_SEQUENCE_TABLE</generator-name>
<key-cache-size>10</key-cache-size>
</automatic-key-generation>


<!-- Note that the autokey generator relies on a table with one record.
The build.sql has DDL that builds such tables for each entity bean -->


</weblogic-rdbms-bean>




Wednesday, September 25, 2002

My review of WebLogic Bible finally got published on Slashdot....

"The BEA WebLogic Server Bible is an enjoyable read. If you have been using WebLogic off and on since before EJB (Enterprise JavaBeans) existed, you will still learn a bunch of new tricks. This is an excellent reference that can be read from cover to cover. The book focuses on small examples with an emphasis of deploying and configuring the examples in the WebLogic environment."

There are plenty of examples of setting up your WebLogic configuration, with explanations of what the different parameters are and when to use them for Servlets, JSP, EJB, JMS, and more; just what you need when you are having those configuration problems and a great reference to have around when you get stuck. If you like going from concept to implementation, then this is the book for you.

Unlike some other WebLogic centric books, the Bible's coverage of EJB CMP/CMR was good. Also, the coverage of performance monitoring was really well done. And, the ideas for optimization and the thought process behind it was also really well done. These are just a few examples of a really well written technical manual--the missing WebLogic Manual.

A couple areas of concern (some just nits):

1) A few times the examples were WebLogic centric when they could have been written them in a cross platform manner (wrt J2EE ). (Note: A prerequisite of this book is a working knowledge of J2EE.)

2) The EJB examples hard coded the JNDI parameters instead of using the jndi.properties file in the classpath, which is the preferred approach for cross platform J2EE development.

Granted, at times you have to write things WebLogic centric to utilize WebLogic-specific extensions to J2EE, but the book also did this at times when it was not really necessary to do so. A J2EE veteran will catch the difference, and a J2EE novice will not. Bottom line: you should have a working knowledge of J2EE before reading this book and there will not be any problem.

Another problem with the book is that it covers WebLogic 6.1, while WebLogic 7.0 is already out. However, the material is still applicable to WebLogic 7.0. The book was released this year as was WebLogic 7.0. This in an unavoidable problem with books focused on such a target market. By the time they update the 1000-page book to WebLogic 7.0, WebLogic 8.0 will probably be out. (Notice I say target not niche... WebLogic's market share is huge.)

Also, in the next edition they should cover the Weblogic specific Ant tags in addition to the console and other means of deploying applications. Ant is the de facto method for building, deploying and testing J2EE applications, and a book like this should reflect this reality.

If you are new to WebLogic, I suggest that you get this book. If you have been working with WebLogic since before the EJB .8 spec., I suggest that you get this book. This book is not a J2EE tutorial, but it covers the basics and focuses on WebLogic specific areas of concern.

Consider this book recommended.



Read: J2EE Container Shootout Summary

Interesting read... mentions XDoclet and the power of EJB CMP.

http://www.rollerweblogger.org/page/roller?catname=Java (Tuesday September 24, 2002 )


Two interesting quotes:

What applications justify the use of EJB?
"""
BEA: Robert says that even for small apps, you should design with future migration to EJB in mind. Use EJB if your developers have the skillset for EJB.
ORACLE: agrees that skillset is important. If you are a database house, you might not want to go the EJB route. EJB is not yet truly mature and does not do all the things that a great database can do.
JBOSS: Mark says: don't access the database directly from Servlets and JSP, use EJB intead. EJB caches data for web applications very well and can be ten times faster than ordinary database access. But Mark doesn't stop there. He goes on to say that some companies allow licensing costs to drive their architecture choices and stay away from EJB because of cost, with JBoss you don't have to worry about licensing costs. From the way the BEA panelist rolls his eyes, I get the feeling that he has come up against Mark before.
"""

Another interesting quote.... about JDO

"""
Do you support JDO and what are your plans for JDO?

JBOSS: we have been supporting JDO for quite a while via Castor and other means. But, JDO has not taken the persistence crown. EJB/CMP is much more powerful than JDO. JBoss is working to decouple the CMP engine from JBoss so that it can be used independently of EJB.
ORACLE: The Oracle app server does not supprt JDO, but our new TopLink product is very close, and may enable Oracle to support JDO in the future.
BEA: does not support JDO and says that JDO is not compelling vs. CMP 2.0.
"""


Also pushes XDoclet.... (another quote)

BEA: Robert says it is very difficult to predict the future, but that he sees that XDoclet-like method and field attribute driven development will be important and that web services will be very important.

Tuesday, September 24, 2002

Someone asked how to setup a connection pool in Resin... I posted the following to Resin group (which worked). Let me try to answer, the most J2EE centric way to accomplish this with Resin. (Please let me know if this is not the most correct way... I know it works,
but...)

Step 1
Add the resource to you web.xml as a child of web-app file after the welcome
file list.

...

jdbc/emp
javax.sql.DataSource
Container

...

Step 2
Add the resource to resin.conf to the as a child of caucho.com




jdbc/emp
javax.sql.DataSource







...

Step 3 copy the JDBC driver to Resin lib

Step 4 Access the data source from you code as follows:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/emp");
return ds.getConnection();

I have some examples if you would like to look at them.
Let me know and I will email them to you. They come complete with an Ant
build script.

Also, if you get a chance check out this tutorial on Resin EJB and XDoclet
XDoclet EJB Tutorial

I am writing a step by step tutorial for XDoclet and EJB CMP/CMR EJB QL.
Since the tutorial is hosted on a WIKI server, it is collaborative, i.e., you can make changes and additions.

I think it has enough to be useful already, but expect it to grow and evolve into a complete J2EE tutorial with XDoclet.

Please try it out:
http://java-tools.eblox.com/index.php?ResinCMPCMRXDocletTutorial

For now it is based on the examples that I wrote for this tutorial EJB Tutorial.
(The examples have been ported to JBoss and WebLogic with XDoclet already)

-------------------

I wrote two chapters in the upcoming Mastering Tomcat Development from Wiley. I wrote a chapter on Struts and a chapter on Ant/XDoclet. The Struts chapter rewrites a model 1 JSP based application to be a model 2 based Struts application, and it uses XDoclet support. The Ant/XDoclet Chapter has examples of using XDoclet for Custom Tags, Struts, Servlets, EJBs and more.

I am trying to get Wiley to release some of the XDoclet parts online.

Mastering Tomcat Development

http://www.amazon.com/exec/obidos/ASIN/0471237647/rickhightower-20/002-5683012-4771231

If they do, any interest in including them with the XDoclet documentation?

Rick Hightower

Agile Modeling and Scott Amber just came up in conversation....
I wrote a review about Scott's book that was published on Slashdot.

I've been waiting for a book like this. If you are doing software development of any kind, you should read this book. Especially if you are doing Extreme Programming and you errantly believe modeling has no place in XP. Or, your doing the Unified Process and you feel that your models and documents are more important than a working system, or you feel you are bogged down in documentation and required artifacts (more likely). Agile Modeling (AM) is a modeling methodology that enhances your modeling endeavors, whatever your process methodology inclination. Agile modeling will help you effectively incorporate modeling into your organization." Read the rest of Rick's review below.


The title is only partially accurate as the book covers a lot more than modeling. I know from experience that picking titles is tricky (you can't please everyone). You don't need to be a UML expert to get value of this book. Any software developer should be able to appreciate it. Modelers, software developers and Yes, managers will find this material useful. In fact you may want to buy a copy and put it on your manager's desk. This book is original and well thought out. It is also well written and very readable. I wish there were more examples of applying the different artifacts in different phases of the XP life-cycle, but there has to be room for the next edition. The depth is appropriate.

Many UP developers (and those working with other prescriptive processes) get bogged down in the tonnage of documents and artifacts that are required. They wonder if they are ever going to have time to actually write the code.

XP offers a methodology for building high quality software fast. However, many XP developers, and I've spoken to them about this very subject on many occasions, find that XP does include time to do models. This books shows how to integrate XP and modeling.

This book sets the record straight about design and Extreme Programming. Actually, Kent Beck set the record straight with the first book on XP when he said 'In the time it would take you to code one design, you can compare and contrast three designs with pictures.' Kent Beck's views were corrupted over the years for various reasons that Agile Modeling explains, as it clarifies once and for all the relationship between XP and modeling.

The book emphasizes that you should model to understand the problems and only apply the right artifacts, i.e., that not all modeling must lead to writing code.

Despite the title, he AM book transcends just being a book on modeling; the book covers many aspects of developing software. Agile Modeling endeavors to be real. By real I mean it talks about real issues and how things are handled in the real world, not the perfect world covered by most books. For example, the chapter on documentation is an excellent coverage of the subject, but not idealized beyond all usefulness.

Like the original XP book, the AM book lists values, core principles and practices. It also adds supplementary principles like 'Content Is More Important Than Representation.' A key lesson from the book is that models are important if they help you understand and solve problems. And, models do not have to be perfect -- in fact they can be thrown away when you are done with them. After all is said and done, 'Software is your Primary Goal.'

The author, Scott Ambler is the author of numerous books (and by numerous I mean a lot) for the Unified Process, and UML. He also contributed to the Mastering EJB Book, and the Java Elements of Style book. All his work in UP seems strange since AM seems to have closer ties to XP than UP, but that is probably my own warped misconceptions of the world. Bottom line, Scott has mastered the craft of writing and I really enjoyed his writing style. The first few chapters seemed a little slow, probably because their content has been covered before in other books. The chapters on AM and XP, though, were informative and useful (as was the chapter on agile documentation mentioned earlier).

If you are doing software development of any kind, you should read this book. It is an informative and enjoyable read.
The original article is here on slashdot http://books.slashdot.org/article.pl?sid=02/05/07/157241&mode=thread&tid=156

Monday, September 23, 2002

Thoughts on JDO....

My opinion, EJB 2.0 CMP CMR is more mature than JDO. Most JDO implementation "don't fully implement the JDO spec. yet".... that said I think JDO will leap ahead of EJB in the near future...

I also think a future version of EJB 2.2 will merge EJB CMP CMR and JDO just like EJB 2.1 merged EJB and web services. There is really no point in having two frameworks that essentially accomplish the same thing. therefore a later version of EJB will embrace JDO and build on top of it instead of replace it... Just my humble opinion. (note this is just a guess... i have not heard of any such activity)
Another interesting blog article....

http://radio.weblogs.com/0107789/stories/2002/07/09/whyILikeWebwork.html

I first heard about WebWork when I was at XPUniverse. I've been using Struts for a while. I find Struts useful, but sometimes ugly and klugy. I am willing to give WebWork a look.
I read an interesting article about EJB at
http://radio.weblogs.com/0107789/stories/2002/05/24/isEjbAlwaysNecessary.html

At some point, I would like to address this article on a point by point basis.

Thursday, September 19, 2002

Create an XDoclet Resin Tutorial....
http://java-tools.eblox.com/index.php?ResinCMPCMRXDocletTutorial

Thursday, September 12, 2002

I am slowly losing steam. The TCC certificaiton stuff took a lot out of me, and I've been running on empty all week. I'll be glad when I can rest.

Wednesday, September 11, 2002

Well, I completed the Together Control Center Certification. I am now Together Soft certified in UML, J2EE, Java and C++.
Well, as soon as I send in the paper work, I am certified to teach the following TogetherSoft courses:


  • How to Build Better Object Models
  • UML Quickstart
  • Java Quickstart
  • C++ Quickstart
  • J2EE Quickstart


The two day training was very informative and I learned a lot about modeling in color and the DNC. I read the book by Peter Coad on Modeling Java in Color a long time ago, but the concepts really came to life when I heard Ron, the chief mentor, explain it.

I've been a fan of the TogetherSoft toolset for a long time.

Sunday, September 08, 2002

In a few minutes I am leaving for the airport. (1/2 hour). It is off to North Carolina then Minnesota. I am going to Together Control Center certification training in North Carolina then I am teaching advanced Swing in Minnesota. I've been preparing for the TCC Cert a lot. Wish me well.

Saturday, September 07, 2002

I've been working on getting TogetherSoft certified a good chunk of this week.
(8/22/02) I just completed two chapters in the upcoming Mastering Tomcat Development from Wiley. I wrote a chapter on Struts and a chapter on Ant/XDoclet. The Struts chapter rewrites a model 1 JSP based application to be a model 2 based Struts application. The Ant/XDoclet Chapter has examples of using XDoclet for Custom Tags, Struts, Servlets, EJBs and more.



Chris Lechner and Andy Barton from eBlox setup and hosted the WIKI for the Java Tools For Extreme Programming Book.
We now have a book errata. We also have a book review section.

"eBlox has been kind enough to sponsor a Wiki for this book. You can share Errata, Suggestions, and Reviews at http://java-tools.eblox.com/index.php"



Alen Williamson wrote:
"It was good to catch up with people, and I have to say, to thoroughly enjoying grabbing some quality face-to-face time with a number of authors including, Joey Gibson and Rick Hightower to name but a few. Their insight into the current trends and technologies was most enlightening, and hopefully I will be able to snaffle a guest editorial from them at some point."

I'd love to do a guest editorial. Ask me anytime.

I am speaking at the following places:


I am speaking on the following topics (both are 3 hour tutorials):

Sunday, September 01, 2002

My wife got tired of qwest dsl. It was going down every twenty minutes. She hooked up cox communication (cable model) and bought a wireless hub. Now I have a wireless connection at home..... All I need now is an espresso machine and a barista, and I am fully wired. errr... I mean unwired.... Wireless to the hub + cox cable modem is faster than qwest dsl. My wife likes techy things... I just wish she would quit beating me at the XBox games.