Sunday, August 06, 2006
Setting up JBoss 4.0.4.GA for EJB 3.0
I have been able to make EJB 3.0 work before using an old version of JBoss.
Now that JEE5 is officially released, I'm trying to revisit my old work.
Here are my experiences so far.
Hopefully, it will help others who might encounter the same problems.
I would appreciate feedback on how I can improve this.
I'm using Eclipse Webtools for development.
Eclipse version: 3.2.0 Webtools version: 1.5.0
JBoss and MySQL for deployment.
JBoss version: JBoss-4.0.4.GA and EJB 3.0 RC8
- After creating new EAR file and EJB file associated together.
I got an error:
An EJB module must contain one or more enterprise beans. Intranet-EJB/ejbModule/META-INF ejb-jar.xml line 5
Explanation: Webtools only support up to EJB 2.1. Since EJB 3.0 doesn't need ejb-jar.xml, we can safely delete it. However, the compiler will give a warning like the one below. Just ignore it.
CHKJ2905W: The EJB Validator did not run because ejb-jar.xml could not be loaded. Run the XML validator for more information. Intranet-EJB Unknown
- After adding an EJB3 class, There are compilation errors because EJB3 libraries are not found.
Explanation: Webtools currently support only up to EJB 2.1. We have to add EJB 3.0 support to the core JBoss installation.To do this, install EJB 3.0 RC8And follow instructions in the INSTALL.html.
EJB 3.0 files not compiling, libraries not found.
For ejb classes:
These files need to be added in Eclipse build path.
Note that you can use the JBoss default setup instead of the all setup as mentioned in the INSTALL.html.
Don't include ejb3-clustered-sfsbcache-service.xml and ejb3-entity-cache-service.xml if you're using the default setup because they are for the JBoss all setup only and not for default setup.
To test, run JBoss and you shouldn't encounter any errors. Try to deploy EJB3Trail.ear to deploy folder and it should work. For now, it will not work because there are missing files. See below.
- There are some missing files that were mentioned in the INSTALL.html.
Forum users are complaining about it here: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=84310.
One of them, Sverker, created an unofficial patch: http://www.abrahamsson.com/jboss-EJB-3.0_RC8-FD-sverker.zip
Download the zip file and read README.txt. The file contains all the needed files to start the server correctly. However, there are still some missing files, which will be discussed below.
- I'm getting an error when running the server.
The error message is:
[ServiceController] Problem starting service jboss.j2ee:service=EJB3,module=Intranet-EJB.jarjava.lang.RuntimeException: Field private javax.persistence.EntityManager com.tougher.intranet.impl.service.employee.UnitServiceImpl.em @PersistenceUnit in error: EMPTY STRING unitName but there is no deployments in scope at org.jboss.ejb3.injection.PersistenceContextHandler.loadFieldDependencies(PersistenceContextHandler.java:358)
Explanation: The keyword here is "there is no deployment in scope". It means there is no EntityManager because there's no Persistence Context. We have to add persistence.xml in the EJB file. We need for it to point it to our DataSource.
After adding persistence.xml, the job is not quite done. Make sure your jdbc jar files are added to jboss lib folder, and then add the DataSource file in jboss deploy folder. Set url, username and password. Restart server and the problem should be gone.
- When running EJB via a client remotely,I'm getting org.jboss.aop.Interceptor not found.
Explanation: Client needs these jars found in <jboss>\client.
Now, even the jboss-EJB-3.0_RC8-FD-sverker.zip file doesn't have the last two jars. I got it from an older version (jboss-4.0.4.CR2).
Honestly, what's with JBoss these days? They seemed to be doing very well prior to this release...
- There's a weird message I get when I run my client
Using ThreadLocal: falseinvoke called, but our invoker is disconnected, discarding and fetching another fresh invoker for: InvokerLocator [socket://10.10.0.2:3873/]connect called for: org.jboss.remoting.transport.socket.SocketClientInvoker@50988
Explanation: It's not doing any harm so I just ignore it. I've seen it being asked about in the forums; no answer so far.
- How to effect changes in EAR or EJB?
After you change something in your EJB or EAR,you can effect the changes by going to Servers->Jboss->Publish. You don't have to restart.
- Can I debug a persistence class?
I'm surprised that we now can. Sweet.
It appears as a stub first when it stops at the breakpoint. After I associated it with the source code, I'm able to step through it.
- Persistence class not Serializable
If your persistence class don't implement Serializable, you'll get an exception.
It is usefull. Thanx.
But did you meet this kind of error message?
10:43:46,703 ERROR [UDP] exception=java.io.OptionalDataException
Gabor from Hungary
Sorry. No I haven't.
I'm pasting the javadoc in here, as this might help you.
It looks like it has something to do with Serialization. Perhaps your classes changed locally but you weren't able to update the classes that were deployed?
Exception indicating the failure of an object read operation due to unread primitive data, or the end of data belonging to a serialized object in the stream. This exception may be thrown in two cases:
An attempt was made to read an object when the next element in the stream is primitive data. In this case, the OptionalDataException's length field is set to the number of bytes of primitive data immediately readable from the stream, and the eof field is set to false.
An attempt was made to read past the end of data consumable by a class-defined readObject or readExternal method. In this case, the OptionalDataException's eof field is set to true, and the length field is set to 0.
Usefull site, I will be using this site for future references.
I just wanna ask if you encounter my error message below. Im using JBOSS-4.0.4.GA AS and NB 5.5 Beta 2 with JBOSS Bundle.
17:29:06,891 WARN [ServiceController] Problem starting service persistence.units:ear=TestEJB.ear,jar=TestEJB-ejb.jar,unitName=TestEJB-ejbPU
javax.naming.NameNotFoundException: Test not bound
Christopher Keith from the Philippines.
I have also the same error and I don't know where the problem is...
10:51:26,783 WARN [ServiceController] Problem starting service persistence.units:ear=EAW1.ear,jar=EAW1-ejb.jar,unitName=EAW1-ejbPU
javax.naming.NameNotFoundException: mysql-EAW not bound
--- MBeans waiting for other MBeans ---
Reason: javax.naming.NameNotFoundException: mysql-EAW not bound
I Depend On:
The mysql-EAW is the name I gave to the data source when creating the persistence unit in netbeans 5.5.
see here: http://imacx.ath.cx/img/eaw-mysql.jpg
Thx for helping me
Apologies to Christopher for the late reply,
this might help your problem.
Have a nice day
Its nice of you to post problems you encountered, so that others may not get stuck there.
I am new to EJB3, can you please email me a simple bare minimal hello world example of EJB3.
I tried making my own, but I keep gettin EJb not bound exception.
my email: mustafa[dot]kachwala[at]gmail.com
I'm sorry, I haven't had the chance to work in EJB for a long time now. I had to revert back to Hibernate 2.1.
Anyway, this might help you. http://www.nabble.com/javax.naming.NameNotFoundException:-DefaultDS-not-bound---Entity-Unit-(Cabin)-in-EJB-3.0-t3185266.html
I created a session bean(stateless) with remote interface..I don't know how to package..I exported the whole EJB project as jar file..I started JBoss and it threw an error..
[ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=Calculator.jar
java.lang.ClassNotFoundException: Unexpected error during load of: com.StatelessCalculator, msg=Bad version number in .class file
So far your tips have been extremely useful!! Thank you.
i am getting the following error when i start up my JBoss server. There are some tables it does not want to create.
16:39:43,014 WARN [ServiceController] Problem starting service jboss.j2ee:service=EjbModule,module=AccountActivationsImages.jar
org.jboss.deployment.DeploymentException: Error while creating table accountactivationsimages; - nested throwable: (java.sql.SQLException: Specified k
ey was too long; max key length is 1024 bytes)
i have tried changing settings in MySQL as well but still get the same error.
Please could you help me??
this has something to do with MySQL...
This might help... http://jira.atlassian.com/browse/CONF-2783