aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB Structure used in Client-Server Program?   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB Structure used in Client-Server Program?   " Watch "EJB Structure used in Client-Server Program?   " New topic
Author

EJB Structure used in Client-Server Program?

neetika sharma
Ranch Hand

Joined: May 19, 2006
Posts: 89
A typical Enterprise Java Bean consists of a
-EJB Home,
-EJB Interface
-EJB bean class

In a client-server environment that's NOT an Enterprise Java Bean or running on an Application Server but instead just a java application that runs on the server, why would someone follow a similiar structure in designing their classes to have a Home, Interface, and bean class?

For instance if a client application (non ejb) was designed utilizing the Model of the MVC design pattern, when creating the Modeling classes one would typically create 1 class modeling the data. But instead utilizing the EJB design, you could create a bean class modeling the data, and have an interface, and also a home class that instantiates a singleton of the bean class or home. This is one scenario.

What would be the reasoning for using a similiar approach to the way EJB has a Home, Interface, and Bean class in a java application (non-ejb app)? Is it because of possible future migration from a traditional client-server environment to an EJB like environment?

Please give some thughts about the same.Also if i am migrating my application which is in JSP servelets to EJB, what will be cons for that.It is going fine with JSP and servelets.Experts please give some suggestions.
[ December 30, 2006: Message edited by: Neetika Sood ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30502
    
150

Neetika,
Let's map EJB to the parts of a non-EJB call to get the business data.
1) Home interface - Factory to create class or a simple constructor call
2) Remote/local interface - An interface describing the available methods. (This isn't required in non-EJB code, but it is good practice.)
3) Bean - The implementation

In non-EJB code, it may make sense to combine 1 & 3 into one class.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30502
    
150

Originally posted by Neetika Sood:
Also if i am migrating my application which is in JSP servelets to EJB, what will be cons for that.It is going fine with JSP and servelets.Experts please give some suggestions.

Not all applications need EJB. If you aren't using security/transactions/etc, using EJB is overkill. This is probably the case for you since you note that it is going fine with JSP and servlets.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

First a client-server application is two ties. The Client tier which has pretty much everything, and the second tier is the backend database.

When you include "but instead just a java application that runs on the server" means that it is now three tier.

You can create such an application, but you will have to code all the services that an App Server gives you with EJBs. In order to get those services in EJB 2.x those Home, Interface classes etc were needed. In EJB 3.0 you only need your interface and implementation classes.

Why you need these? Cleaner seperation, translates into easier maintenance. In you "non-ejb" application, I wouldn't create a Home object myself.

If you are building a web application, you will need Servlets and JSP, it wouldn't be those classes being converted into EJBs, EJBs would be used in conjunction with them when you really need transactions and the other services EJBs might provide for you.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
neetika sharma
Ranch Hand

Joined: May 19, 2006
Posts: 89
Hi Jeanne and Mark,

Thanks for responding and clearing my doubts.Now I understand that EJB can be used where I need transactions and the other services EJBs might provide.and as per Jeanne if I am not using security/transactions/etc, using EJB is overkill.

If you people can still clarify me...how EJB is overkill for a simple Web application(cons of EJB), it will be really helpful for me.
Actually I was thinking to replace my service layer(containing interactions with DAO and business logic)in my simple Web application with EJB.

Hope to hear some explanation from you:-)
[ December 30, 2006: Message edited by: Neetika Sood ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30502
    
150

Neetika,
Let's look at an example.

Suppose I have a simple web application that displays the classes offered in a semester. Its read only, so I don't need transaction support. Its public knowledge so I don't need security. EJB wouldn't provide me with much benefit here. Meanwhile it would introduce unnecessary complexity (a con), so I would go without it.

Now suppose I have a more complicated web application that allows me to register for courses. I do need transaction support to provide "all or nothing" operations so students can drop one course and add another. And I need security because I don't want people dropping the courses of others. So EJB could be of use. (Of course it doesn't require EJB. Some other way of providing these services is fine too.)
neetika sharma
Ranch Hand

Joined: May 19, 2006
Posts: 89
Thanks Jeanne for responding.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB Structure used in Client-Server Program?