Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My 1st Stateless session bean App. What's my fault?

 
al nik
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I'm new with ejb.
I'm trying to do my first example with stateless session bean.
So I have one ejb3 jar project with something like
an Entity
Student.java

a service Interface
StudentService.java

it's implementation
StudentServiceBean.java

persistence.xml



(can I use tomcat6 to deploy my session bean? I'm thinking tomcat doesn't support ejb3.. I'm seeing only glassfish and jboss deployment examples!)

under a client project I have a class like


when I try to run the main method I get NullPointer on service.createStudent(....

what I miss?
thanks guys
[ December 17, 2007: Message edited by: al nik ]
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You certainly CANNOT use tomcat to deploy your ejbs.
Make sure you know the differences between an EJB container and a web server.
 
al nik
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I thought tomcat had an ejb container with the new versions :roll:
so now I'm trying on glassfish v2.

if I try to do something like this

InitialContext ctx = new InitialContext();
StudentService bean = ( StudentService) ctx.lookup("com.StudentService");

it works!

My client is in the same server (localhost). I don't understand how can I create a client that lookup an ejb on another server to do some work...
[ December 17, 2007: Message edited by: al nik ]
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, 2 things here :
1) in your example you use a Local interface, so the lookup is local
2) had it been a remote interface, it would have worked too:
in initial versions of the EJB specification, an EJB always had a remote interface extending the javax.ejb.EJBObject interface.
So EJBs were always defined as remote objects, adding unnecessary overhead to EJB calls in situations where the servlet or other calling module is co-located with the EJB.
So in the version 2.0 of the specification came the Local interface.
The lookup can then be local, that is in the same JVM.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic