views:

401

answers:

3

Hello,

I am using Netbeans 6.8 and Glassfish v3.0.

I created an ejb module and created entity classes from database and then created stateless session bean with remote interface. Say eg.

 @Remote
public interface customerRemote{
    public void add(String name, String address);
    public Customer find(Integer id);
}

@Stateless
public class customerBean implements customerRemote{
    //implementations of methods
}

Then i created a new web application. But now how do i access remote ejb's in my web application. I could lookup a bean with jndi name but what i want to know is, what type of object it will return? How do i typecast it in customerRemote? I don't have any class named customerRemote in my web application. So, how do i do it? Also, what about the entity class Customer? There is no such class named Customer in my web application also. All ejb's and entity classes are in separate ejb module. Please help me :(

+3  A: 

How do i typecast it in customerRemote? I don't have any class named customerRemote in my web application. So, how do i do it? Also, what about the entity class Customer? There is no such class named Customer in my web application also. All ejb's and entity classes are in separate ejb module.

Your web application must depend on a library that contains these classes and interfaces. Then you will be able to import the interface and typecast as usual. You have two approaches:

  • All in one jar. This seems to be what you have now. In this case your web app needs to depend on this jar.

  • Split API and implementation. A better approach is to split your ejb module in two jars: one jar myModule-api contains the classes that belong to the API of your module. In this case that would be customerRemote and Customer. And another jar myModule-impl contains the implementation (the implementation depends on the API of course). Then in your web app, you only need to depend on the API which is in myModule-api.

ewernli
+1  A: 

Hi;

I´m using eclipse 3.5.2, EJB 3.0 and Glassfish 2.1 but I´m sure that this will work for you to.

Well, first of all I have created an EJB proyect that will be deployed as a stand alone EJB module on the container, and another project that is in fact a web application that use a single servlet for testing.

I can resolve the same problem adding the next parameters to the @EJB declaration on the servlet that invoques the bean:

public class SimlpeServletClient extends HttpServlet { . . . @EJB(beanInterface=ISimpleJob.class,mappedName="ISimpleJob") ISimpleJob statelesBean; . . . protected void doPost(HttpServletRequest ...){...}

. . . }

And this is the structure of the bean that implements the interface exposed to the servlet:

@Stateless(name="SimpleJobBean", mappedName="ISimpleJob") @Remote( { ISimpleJob.class }) public class SimpleJobBean implements ISimpleJob { . . . }

As you can see, it seems like your client only knows the interface to work with, but dont tell to the server what resource can fullfill the request.

I hope youl find this helpfull, sorry for my poor english. I speak spanish!

Daniel Gil

Daniel
A: 

Also, what about the entity class Customer? There is no such class named Customer in my web application also. All ejb's and entity classes are in separate ejb module.

If I use the all in one jar approach

I get a Class not found exception on Customer. Exception while loading the app : org.glassfish.deployment.common.DeploymentException: java.lang.NoClassDefFoundError: entity/Customer

I am completely lost on how to create a new object from entity Customer inside the Web Project refering to an allready running ear structured application

Horst Henkel