wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Java EE 5:persistence, web and ejb alltogether Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Java EE 5:persistence, web and ejb alltogether" Watch "Java EE 5:persistence, web and ejb alltogether" New topic
Author

Java EE 5:persistence, web and ejb alltogether

Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Hi to everybody,
I've created an ear with the following structure:


I'm using JBoss 4.2.0.

The file 'persistence.jar' contains a persistence unit and, if deployed as standalone, it works.
The file 'ejb.jar' contains a stateless session bean that accesses to the persistence unit.

If I deploy my ear, JBoss complains when trying to deploy the session bean, dumping that it cannot resolve a dependency from the persistence unit.
It seems like the deployer can't see the 'persistence.jar' element: in fact, in the logs there is no trace about the deployment of my persistence unit.

Thanks a lot in advances!


SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="http://www.enthuware.com" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
krishnamoorthy kitcha
Ranch Hand

Joined: Feb 04, 2006
Posts: 96
Hi

Can you give the Exception log or Exception details ?
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Thanks for the response!

Sorry, I'm not at my home station.
But consider that I do not receive a stack trace error: simply, JBoss informs me that the ejb deployment is incomplete because it cannot find the persistence unit referenced.

Thanks!
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Hi guys,

I partially solved my problem: I had not specified my persistence.jar file as an ejb module in application.xml.

Now, the deployment works correctly, but I can't find the correct name for the session bean: I mean, my servlet can't find the remote interface (NamingNotFoundException).

I have never really understood the jndi naming for external resources: when I have an ejb, I have to:
1. Set an ejb-ref in web.xml
2. Add an application-server specific xml file that maps the jndi name with the name of the ejb

Is it correct?
What should I do if my application server is JBoss?

Thanks a lot in advances...
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Hi guys,

Today, for the first time, my ejb+persistence+servlet...Worked!

However, I don't yet understand the meaning for ejb-ref in web.xml. In my application, I simply didn't put anything in web.xml and it worked.

Can anybody explain me the meaning for ejb-ref for web.xml?

Thanks in advances
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

ejb-ref is useful if you need to reference an EJB from your servlet.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Hi,
thanks for your response.

Ok, I thought it, too, but today my servlet has been able to access to my stateless session bean without using any ejb-ref.

Consider that I'm using java enterprise edition 5 and I'm using the @Remote and @Stateless annotations...

Thanks a lot!
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

I guess that's because you use the global JNDI to lookup your EJB. Thus, you don't need to use ejb-ref at all.
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Hi,
thanks for the response.
Well, I think it is, but when I tried to set an ejb-ref, the application server complained because it expected at least an 'home' element.
Aren't annotation enough for the application server?
Consider that my web.xml is 2.5 version.

Thanks in advances!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java EE 5:persistence, web and ejb alltogether