Thursday, April 19, 2007

Journey to the Enterprise Edition

I've started using Java EE 5 for the past few days.The very first thing is to choose a Java EE container.I downloaded GlassFish and JBoss and start evaluating them.I started my experiment on GlassFish V2.I got my first hello-world ejb working on it,no problem. So I started to port my application which is using Hiernate to communicate with database.Now the problems arised,GF has pre-defined Oracle Toplink as the default persistence provider ,so if I want to use Hibernate,I need to specify the provider in my persistence.xml.Fine, I can live with just modifying one file and using my preferred persistence provider.Then I also need to change the xml declaration with the correct schema.Then I deployed again,error occured. I spent the next 4 hours to make it work including moving the necessary libraries to server library folder.And the strange thing is,although i already specified the persistence provider, but sometimes it still pointing back to Toplink.So i have to use the admin console to stop the application,then start the application again.Did I mention that you need to include log4j.jar in you EAR/lib in order to use it?Yes,you need to.

I was so fed up with GlassFish,but don't get me wrong,its not mature yet,that's all.So I switched to JBoss 4.05.Ok,i just put my EAR in,and it runs.Then i found some other strange problems,when connecting to database,such as

Caused by: java.lang.ClassCastException: org.hibernate.ejb.EntityManagerFactoryImpl cannot be cast to org.hibernate.ejb.EntityManagerFactoryImpl

Weird,rite?How come the class cannot be type casted to the same type of class?Probably no many people out there met this kind of strange problems.So,googling wouldn't really helps.After another 5 hours I found out that the problem is because my EAR file contains some libraries JBoss has.I remove those duplicated libraries in my EAR file,and it works.

I shall continue next post with some of the features provided by Java EE 5.

No comments: