*
The moose likes EJB and other Java EE Technologies and the fly likes Is this good design 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 "Is this good design " Watch "Is this good design " New topic
Author

Is this good design

satish pune
Ranch Hand

Joined: Sep 04, 2003
Posts: 44
In a previous project where we were using struts the action classes were making calls to methods defined in stateless session beans .

These bean methods were then making calls to static methods defined in a separate class - which we termed as our Business classes

These Business classes would interact with the database .

My question was - in case of retrieving data from the database - ( using select queries ) is it still necessary to make calls through the EJB Layer ?

In case of simply retrieving data is this not an overhead ?
What advantages/disadvantages does this approach incurr ?

Regards ,
-satish
Edward Kenworthy
Ranch Hand

Joined: Oct 05, 2003
Posts: 66
Frankly that sounds like an awful idea: calling static methods on *business* objects to interact with the databse. Where do I begin in describing what's wrong with this approach.

Firstly: static methods are effectively global so you've made you're entire app dependent on those classes.

Second: You've hard coded your dependency on those classes: you couldn't for example use another object that implements the same interface to substitue: how do you test? How do you migrate to another environment?

Third: Well third you're using EJBs but then let's just say EJB CMP is an abomination and BMP is worse...

Have look at Hibernate which is a brilliant ORM library: and in case you're desperate to stick with EJB (some kind of masochist huh?) then a) you can use Hibernate from Stateless Session beans and b) Gavin King, the lead dev for Hibernate, is also on the EJB 3.0 CMP committe and reports EJB 3.0 CMP will look an awful lot like Hibernate.

Edward

If JavaRanch had sigs mine would say: Burn EJB and their creators!
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30944
    
158

Satish,
The decision of whether to go through the session bean layer depends on whether you need transactions/security/scalability.

I second that you should avoid the static calls. Even if you are stuck with them, create a wrapper to abstract it away.


[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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30944
    
158

Edward,
JavaRanch actually does have sigs. If you edit your profile, it's the last item in the first section.
Edward Kenworthy
Ranch Hand

Joined: Oct 05, 2003
Posts: 66
Originally posted by Jeanne Boyarsky:
Edward,
JavaRanch actually does have sigs. If you edit your profile, it's the last item in the first section.


Yeah I know: I just thought my comment would be funnier if I pretended they didn't. Kind of like when Roger rabbit escapes from the handcuffs and Bob Hoskyns asks him why he didn't do it earlier: "because it wasn't funny then.". Oh well maybe not
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30944
    
158

Edward,
Oh! I get it now. Sometimes it takes a while for a joke to sink in
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is this good design