• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

JBoss5.1 EJB3 JSF1.2 integration problem  RSS feed

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm following simple examples like this one:
http://gochev.blogspot.com/2009/10/javaee-5-jsf-jpa-ejb3-using-eclipse.html

But i can't get the stateless bean from the EJB module i've successfully deployed on JBoss no matter what i try.
I get:

root cause
java.lang.NullPointerException

i tried with @EJB,
w/ and w/o @EJB mapped name,
w/ and w/o ejb-jar.xml and jboss.xml (which i doubt i configured properly anyway but the example don't say anything about them,
and with new InitialContext().lookup(...) too

at best i got a:
javax.naming.NamingException: Could not dereference object [Root exception is ja
va.lang.reflect.UndeclaredThrowableException]
at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingC
ontext.java:1504)

...
when i probably managed to integrate it but run into another problem.

some example code:


The backing bean - from which i try to display something in a JSF/JSP page and can't:


The interface


The bean



The entity
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, to get a reference to the same ejb, use sessionContext.getBusinessObject(Greeter.class)(inject sessionContext with @Resource) instead of doing InitialContext ctx = new InitialContext(); greeter = (Greeter) ctx.lookup("GreeterBean/remote");

If it still doesn´t work, please put the full stack trace
 
Tudor Raneti
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, sorry I've been out during weekend for I have no internet at home momentarily.

Injecting a @Resource would probably work on JBoss as it is one of the solutions I also read about (i will give it a try and update when i test it on JBoss - although i have doubts, since @Resource injection is in the same category as @EJB)

I will describe the solution I found, although JBoss complains about it.
(I will update here with the WARN message after I apply the solution)

The situation was that when i try to inject using @EJB annotation, JBoss gives ERROR:
Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Resolution should not happen via injection container

But when i get the context like this in User.java:

Note i added getInitialContext() and commented out the @EJB injection


It works, although in this JBoss instalation / example it also gives a bizarre error that doesn't seem to affect anything:

[STDERR] javax.naming.NameNotFoundException: GreeterBean not bound





 
Tudor Raneti
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the problem.
Deployed and exploded EAR directory names mustn't end in .ear (Eclipse was deploying like that) - as soon as i renamed w/o the .ear it started working.

I'll leave it unresolved for the problem with @EJB annotation that won't work
 
Tudor Raneti
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, double post
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The NameNotFoundException is most likely because you are using the wrong JNDI name. While deploying as a .ear the (default) JNDI name of the bean is different from what you use when you deploy as a .jar. See this for more info.

I guess when you removed the .ear extension, it probably is considering it to be a .jar (which is a bit odd actually). Anyway, rename it back to .ear (if it indeed is a .ear file) and then change the lookup code to use the correct JNDI name.
 
Tudor Raneti
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. This also fixed the @EJB "Resolution should not happen via injection

container" problem. Here it sais more:

http://stackoverflow.com/questions/3844453/resolution-should-not-happen-via-injection-container-error

I did go over that one bit of info but I didn't couple it with this:



which can actually sit in the the

EAR_project_name.ear/EJB_project_name.jar/META-INF/jndi.properties, while the

WAR_project_name.war references the EJB_project_name.jar (Eclipse -> build path

->projects -> add)



... which isn't actually needed because JBoss provides it by default ...
Glad it's finally sorted out.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!