• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DAO and EJB etc..

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I use a DAO with my EJB do I have to include that DAO class and package in my EJB Jar File that is deployed to the remote server?

In this case then the DAO class, and the EJB Class files also must reside on my Web App Server(a different physical machine)?

Thanks.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stu,
The caller of the DAO needs the class file available. It is common to have the remote client call a session bean to insulate it from change. The session bean can call the DAO which calls the EJB. You don't want to keep redistributing the DAO everytime something changes.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you think that the EJB and DAO would require also being on the Web Server.

You should look at the chain of calls as each call is calling down to a layer below it. And one layer should never call a layer above it.

So with a Web Server to call an EJB, the Web Server will need the EJB interfaces but that is all. The Web Server will lookup the EJB from the EJB Container and get back a proxy object. The EJB in the EJB container calls the DAO, so the DAO will only ever reside in the EJB Container. No other layer above should be calling the DAO directly.

Mark
 
Stu Higgs
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks both Jeanne and Mark for your replies.

Why would you think that the EJB and DAO would require also being on the Web Server.



I'm brand new at developing with EJB and distributed systems. Basically I have little knowledge regarding the packaging requirements, project structure, and deploying of Enterprise Applications, but I am learning by hand coding deployment descriptors, and building with ANT, no Deploy Tool and I like doing it this way!

Specifically, while I was making the EJB more useful by adding some Arguments and Params to the methods, I recompiled the EJB classes and deployed the EJB jar without redeploying the Web App, then I received a Marshalling Exception. I fixed it by redeploying the web app which also contained all of the EJB Classes and not just the Interfaces. My Web Application contained all of the EJB files because I build the EJB files from within a directory in the Web application project and then deploy the EJB jar separately to the EJB server. This led me to believe that I needed the EJB Class and Interfaces in both Web App and EJB Jar. Hope that makes sense the way I explained it.

Now I know all that is required in the Web Application are the Interfaces, and I completely understand what you are saying about the DAO. Thanks for your help in clarifying this.

Stu
[ April 06, 2007: Message edited by: Stu Higgs ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I understand your plight very well. The issue that you see is related to what we call ClassLoaders. And without explaining ClassLoaders right now, it is a heavy topic.

What you need to do in your WebApp is make sure you are doing a lookup and not trying to create EJB classes directly. OK but the real thing is the packaging. What you will learn in a bit is to package your application into an .ear file that will contain both your .war and your .jar file.

What an ear does is save from having to do a remote lookup of your EJBs. If both the jar and the war are in an ear, the App Server will make sure the classes are all loaded by the same ClassLoader and you don't get a Marshalling Exception.

Does that help.

Mark
 
Stu Higgs
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,

Thanks for your reply. It does help and also raises another question or two or three...

Background:
My EJB.jar is currently deployed to a separate Managed Server named EjbServer and the Web Application is on another managed server named WebAppServer. Currently the two managed servers are on the same physical machine but I imagine in the real world they may be on separate machines(?), where each one will be registered with an Administration server as a managed server?

Right now I am looking up my EJB like this from Servlet:

//move to ServiceLocator
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://192.168.1.3:8002");
Context ctx = new InitialContext(ht);
Object h = ctx.lookup("HelloWorldEJB");
home = (IHelloWorldHome)
PortableRemoteObject.narrow(h, IHelloWorldHome.class);

My question is if my EJB's are on a separate physical machine from the Web Application how can I deploy both Web App Module .war and the EJB Module in a single .ear file? Is there some deployment descriptor in the EAR file that specifies which managed server will host the EJB Module and which managed server will host the Web App Module? Does the EAR file get deployed to or by the Adminsitration Server? Very confusing right now! Thanks for your help.

Stu
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your case where they are really two seperate server, meaning different JVMs running. In that case, your web application will do remote lookups on the EJBS, so the war file that is deployed on the seperate server will only need the Remote interface, based on EJB3. In EJB 2.x I think you also need the Home objects, but it has been a while since I used EJB 2.x that I can't remember, nor do I really want to remember pre EJB3 times.

Mark
 
Stu Higgs
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,

Thanks again for clearing things up about the interfaces and look ups. Much appreciated.

Stu
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic