Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with EJB lookup on JBoss 7.1

 
Rodrigo Sasaki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this post should be here or on JBoss Forums. but here I go

I'm trying to do an EJB lookup on JBoss 7.1.0 like this:



which works fine on GlassFish, but didn't work on JBoss... when I get to the lookup line it just "freezes" waiting for a response I imagine, and the deployment times out..

then I read this thread, explaining how to do it.. then I tried it like this



and still.. same problem..

don't know how to fix this, has anybody had a problem like this here?

here is the EJB classes.. in case there is anything relevant there



and the implementation



the ejb.module is in a .jar inside my ear

Thanks!
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe JBoss 7 logs all EJB JNDI names at startup, for local and remote lookups.
That might be worth checking out in the server.log file.
 
Rodrigo Sasaki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True...

I checked it and the JNDI lookup name is exactly how I was using it..

java:global/my-ear-app/my-ejb-module/FriendBOImpl

that's what I don't understand, I try the lookup and it just freezes, don't know if I'm missing configurations on JBoss or on the EJB
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said you were "trying to do an EJB lookup on JBoss 7.1.0", but from the code sample you provided it looks like you're using the JBoss client API to do a remote lookup, correct? From a standalone client?

 
Rodrigo Sasaki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First.. sorry about the duplicate, I'm new at Javaranch.. it won't happend again.

Second,

I have a classe in my model package doing the lookup, so I guess you are right.

The actual problem is that it worked on GlassFish, and now that I'm using JBoss 7.1.0 it doesn't work anymore.

Any idea what it might be?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class in your model package is doing the JNDI lookup, and that package is part of the deployment to JBoss?
You said the EJB you're trying to lookup is packaged in a .jar file within an .ear archive.
Is you model package in that same .jar file? Or maybe packaged in of a .war file included in the .ear or deployed separately?
Perhaps we should start with how your deployment(s) is/are structured and take it from there.
 
Rodrigo Sasaki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can probably tell.. I'm "junior" at all this hehe..
Never done any work with EJB before, so I'm sorry if I say any stupid things..

the ear has the following structure:



any notes?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, so you want to do a look-up of an EJB packaged inside the market-cadastro-ejb.jar archive from a class inside the market-web.war that's part of the same .ear deployment.
A local JNDI lookup should work in that case using the java:app namespace, but I would take a different approach altogether.
Instead of manually performing a look-up that couples your code to JNDI, in my opinion, you'd be better of using dependency injection and have JBoss figure out how to obtain a reference to the EJB (via JNDI somwhere in the background). Have a look at the @EJB and @Inject annotations


 
Rodrigo Sasaki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey.. I tried using @Inject on my attribute, just adding the annotation like this:



and it didn't work, the attribute was null and I got this error:



I even made a qualifier to try to fix this but it didn't work, any ideas?

I'll keep looking into it, see what I can find
 
Rodrigo Sasaki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't get it to work..

but then again.. why isn't my lookup working the same way it was before on GlassFish?

is it wrong to do a lookup like that on JBoss?
 
Rodrigo Sasaki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh.. I see what you meant.. the Injection was just a suggestion for better use of the technology..

but I tried the static way and it didn't work.. JBoss gave me these JNDI names:

java:global/market-ear/market-cadastro-ejb/MarketBOImpl!br.com.vemac.nagumo.model.bean.vo.sistema.MarketBO
java:app/market-cadastro-ejb/MarketBOImpl!br.com.vemac.nagumo.model.bean.vo.sistema.MarketBO
java:module/MarketBOImpl!br.com.vemac.nagumo.model.bean.vo.sistema.MarketBO
java:jboss/exported/market-ear/market-cadastro-ejb/MarketBOImpl!br.com.vemac.nagumo.model.bean.vo.sistema.MarketBO
java:global/market-ear/market-cadastro-ejb/MarketBOImpl
java:app/market-cadastro-ejb/MarketBOImpl
java:module/MarketBOImpl


but the ones with java:app

cause the following exception:



and the other ones give me the "freezing" error
 
Joshua Davis
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle Klap wrote:Right, so you want to do a look-up of an EJB packaged inside the market-cadastro-ejb.jar archive from a class inside the market-web.war that's part of the same .ear deployment.
A local JNDI lookup should work in that case using the java:app namespace, but I would take a different approach altogether.
Instead of manually performing a look-up that couples your code to JNDI, in my opinion, you'd be better of using dependency injection and have JBoss figure out how to obtain a reference to the EJB (via JNDI somwhere in the background). Have a look at the @EJB and @Inject annotations


Jelle is right. Using EJBs deployed in an EAR from the WAR deployed in the same EAR is best done by injection. Without knowing why you're doing a JNDI lookup, or what kind of object needs the EJB, it's really hard to offer any more help.

@Inject is a CDI annotation. If you want to use that, you'll have to set up CDI in your application and learn to use it (I highly recommend this). I don't see enough information about the packaging to tell.

@EJB is an EJB3 annotation. This should work if your application is packaged properly. However, I've noticed that your EJB is stateful. That can change things a little because the container needs to know more about the state of the thing that is injecting the EJB.

Either way, most of the time you should not need to do any JNDI lookups inside a JEE6 application.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic