Wednesday, 6 May 2009

1-How to Develop Container-Managed-Persistence Entity Beans

This article is about how I managed to build CMP Entity Beans using the Developing Container-Managed Persistence Entity Beans example of tinptB ‘s Blog: EJB in 21 Days: http://ejbvn.wordpress.com/
I appreciate her excellent English, which makes a soothing effect while trying to break through difficulties.

The difference of my work to TINPTB’s is first my work is complete and contains everything necessary to work.
TINPTB’s mission is more about teaching EJB’s thus she concentrates on providing the concise source necessary for creating them. He also provides necessary deployment descriptor scripts for both WebLogic and JBOSS. At this point her work begins to get questionable due to the different versions etc…

My solution works on Jdeveloper 11g(only the client not the deployment), WebLogic10.3, wlfullclient5, apache-ant-1.7.1 and mysql-essential-5.1.30-win32, mysql-connector-java-5.0.8 and Toad for MySQL 4.1 Freeware.

The first difficulty I had was the name used namely order is actually considered a key word by WebLogic 10.3,
Thus I had to change the CMP Entity Bean to XXXARS, ARS being the initials of my name.

Second, TINPTB does not need tomention that there has to be a jndi.properties file somewhere. He may be using the WebLogic console or some other tool instead…???

1- I created/copied the OrderXXX files as given in EJB in 21 Days. I had to change the library name(cmpex).
I also put the ejb-jar.xml, weblogic-ejb-jar.xml, weblogic-cmp-rdbms-jar.xml files into src/META-INF directory. I put the Client.java and jndi.properties also in the src directory. So, the directory structure is:
BMPex
src
Bmpex ..........................META-INF ...........Client.java ......jndi.properties
OrderHomeARS.java ....ejb-jar.xml
OrderARS.java ..............weblogic-ejb-jar.xml
OrderARSEJB.java .......weblogic-cmp-rdbms-jar.xml

At the same level with src lies:
Lib Build Deploy build.xml
wlfullclient5.jar

But also, in your weblogic domain’s lib directory, by the way I use DefaultServer;
C:\oracle\Middleware\jdeveloper\system\system11.1.1.0.31.51.88\DefaultDomain\lib
should include
mysql-connector-java-5.0.8-bin

2- I changes all names ‘order’ to ‘orderARS’. I changed ‘ch11’ lib names to ‘cmpex’. Most important,
There is a small discrepancy in the definition of
<weblogic-rdbms-jar>
<weblogic-rdbms-bean>
<ejb-name>OrderARSEJB</ejb-name>
<data-source-name>styejbDB</data-source-name>
If I give data-source-name above it asks for the JNDI name. So, I entered the JNDI name there.
3- I deployed with WLST as my WebLogic console does not work (or exist at all for some mysterious reason).

connect('weblogic','weblogic','t3://localhost:7101')

deploy("CMPent","C:/CMPentity/deploy/CMPent.jar" "DefaultServer",securityModel="Advanced", block="true")

Here, the library CMPEntity is the place where I used a build.xml file with Ant to compile and create the CMPent.jar. I also used ANT RUN command to run the client here. You may find this build file towards the end of this BLOG entries series.

If something goes wrong about the data source definition or ejb’s make sure that the JNDI tree has corresponding entries. For that, you can use
help(‘trees’)
jndi()
help(‘jndi’)
and so on…