Dear Ranchers, I am learing EJB , I am confused by as simple question,: 1)Developing an application using ASP or JSP is three tier or two tier, like simple data retrieving and posting to database. 2)Building app using EJB are really three tier I agree with it , but is the load balancing and failover are the only adantages achieved by EJB's if we go for EJB rathr than JSP. Hopes for a deailed reply. Yasir Qureshi SCJP2
Kyle Brown
author
Ranch Hand
Joined: Aug 10, 2001
Posts: 3878
posted
0
There are a number of advantages of using EJB's, including: (1) Object-relational mapping (provided by CMP) (2) Distribution (the 2-tier/3-tier thing you mention) (3) Object-level security All of these are useful and good, but can also be done using alternative technologies, not requiring EJB (like for instance using JDO for the first and RMI for the second). But most importantly EJB's also give: (4) Automatic transaction management with 2-phase commit crossing multiple datasources. The last one is the killer. If you really need to build a system that needs transactions that cross 2 databases or a database and a JMS or JCA datasource (like a messaging system or an enterprise system like SAP) then EJB's are the only game in town. You can't do that in JSP alone, period. Kyle ------------------ Kyle Brown, Author of Enterprise Java (tm) Programming with IBM Websphere See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
Kyle, Your last killer point is some what iffy. Because using DAO pattern, RMI, service locator pattern and JMS we are able to access multiple databases at our work. (ofcourse we started using websphere recently to get the advantages of message driven beans etc). But your last killer point is not completely true to my knowledge. Kishore.
Originally posted by Kyle Brown: last one is the killer. If you really need to build a system that needs transactions that cross 2 databases or a database and a JMS or JCA datasource (like a messaging system or an enterprise system like SAP) then EJB's are the [b]only game in town. You can't do that in JSP alone, period. [/B]
would this messaging & database transaction be a solution to a eCommerce problem that I've got? in my app, a customer can order something from the shop and it generates and entry in the database and an email to a delivery firm. can i have those in one transaction? the way i see it, if I save the order in the database as sent and then the system goes down without sending the email, i'm stuffed. if i do it the other way around, by sending the email and then the system crashes without saving it in the database, the customer gets the order for free. either way i'm stuffed. adam
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Kyle Brown
author
Ranch Hand
Joined: Aug 10, 2001
Posts: 3878
posted
0
Originally posted by Kishore Dandu: Kyle, Your last killer point is some what iffy. Because using DAO pattern, RMI, service locator pattern and JMS we are able to access multiple databases at our work. (ofcourse we started using websphere recently to get the advantages of message driven beans etc). But your last killer point is not completely true to my knowledge. Kishore.
There is no way that you are using both of the databases (meaning something like both Oracle and DB2) transactionally in Java in the same transaction without using EJB's. XA support requires a transaction manager -- the only transaction manager defined for Java is an EJB server. The only other things that can act like this are TP monitors like CICS, Tuxedo or ENCINA. Kyle
Originally posted by Adam Hardy: would this messaging & database transaction be a solution to a eCommerce problem that I've got? in my app, a customer can order something from the shop and it generates and entry in the database and an email to a delivery firm. can i have those in one transaction? the way i see it, if I save the order in the database as sent and then the system goes down without sending the email, i'm stuffed. if i do it the other way around, by sending the email and then the system crashes without saving it in the database, the customer gets the order for free. either way i'm stuffed. adam
Well, unfortunately, SMTP isn't an XA datasource. It won't participate in the transaction. If you wanted to decouple the SMTP from the rest by putting a JMS queue in between and then relying on the transactional attributes of the Queue to either (a) ensure the email is sent or (b) put the message making the request back on the queue, then that would work. Kyle
sorry, should have realised messaging was that sort of messaging and not SMTP. well if i can use JMS to make sure the mail definitely gets sent, then i presume from what you say that i can include the JMS in a transaction, i.e. if the JMS fails to create a message in the queue to the email server then it will rollback the transaction?
Originally posted by Kyle Brown: Yes, almost all J2EE application servers support some sort of JMS messaging with transactional semantics. Sounds like the beginnings of a design here... Kyle
In fact, I believe that EJB 2.0 requires JMS messaging support.
------------------ Tom Sun Certified Programmer for the Java� 2 Platform Moderator of the forums: J2EE and EJB Other Java APIs
Originally posted by Kyle Brown: Sounds like the beginnings of a design here... Kyle
well i'm trying to get my arguments together to push for a 3 tier solution to our corporate internet, so i can re-use some of my code (instead of having to rewrite it all the time in different languages for different little websites - like result set paging, shopping carts etc). actually my worst problem is that my senior colleague who hasn't programmed for a while said out of the blue that 'EJB wasn't reliable enough yet' - how do you prove something like that?
Matts Smith
Ranch Hand
Joined: Feb 03, 2001
Posts: 113
posted
0
Originally posted by Adam Hardy: actually my worst problem is that my senior colleague who hasn't programmed for a while said out of the blue that 'EJB wasn't reliable enough yet' - how do you prove something like that?
the guy is dead right. Also EJBs are not easy to implement for junior staff. I've seen more EJB projects fail (which I had nothing to do with BTW) than anything else. The only thing usable in EJB so far is stateless session beans when you need to make a transaction across multiple XA ressources. Wait for the EJB 5.0 specs
While I disagree that EJB's "aren't reliable enough yet" (I've seen a lot of projects fail, but I've seen a *heck* of a lot more succeed, and I generally work with about 60 customers each year) I would also concur that in 80% of all cases, all that you need are stateless session beans. By all means START THERE. If you need the other features (entity beans or *ugh* stateful session beans) then add them only as needed. What's more you DON'T need many stateless session beans. Most of the most successful designs I've seen have no more than a dozen stateless session beans in the WHOLE system. The way to achieve this is through the use of the Session Facade pattern and plain old good OO design. See here: http://www7b.boulder.ibm.com/wsdd/library/techarticles/0106_brown/sessionfacades.html for more information on the session facade pattern, or read the wonderful Core J2EE Patterns book. Kyle ------------------ Kyle Brown, Author of Enterprise Java (tm) Programming with IBM Websphere See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
Adam Hardy
Ranch Hand
Joined: Oct 09, 2001
Posts: 563
posted
0
well, i don't propose to launch myself alone into the big bad world of distributed java web apps - there are consultants available to my dept for days or weeks of on-site work who know their stuff, but i'm the only one in the dept who's actually going to make it happen, if at all. i come from a Microsoft web-app background and while the details of the Microsoft approach are going to be different to MVC & Session Facade etc, I'm pretty sure my overall knowledge of software architecture, component-oriented development, OO design etc are all translatable to Java. Tell me if I'm wrong! i was thinking of ways of illustrating the current state of the development world - and i got these stats from jobserve, a european recruitment website. microsoft VB components in the MS transaction server are definitley accepted as a stable, reliable solution, judging by the number of large companies basing their IT architecture on it - and these are job numbers on offer in europe this week on jobserve, straight VB and in comparison DCOM & MTS: VB 2400 jobs DCOM & MTS 540 jobs in the java job market, the stats are: Java 2330 EJB 273 so basically my conclusion is that EJB is up there in the same order of magnitude as Microsoft for component-based, distributed apps, although somewhat behind. Based purely on that, I would say that EJB is accepted as reliable. Plus of course there is the huge volume of books & literature and all the web resources out there pointing to the fact that EJB is accepted. As I said earlier, it's my managerial, ex-programming colleage who i need to get to update his opinions, unless someone can convince me i'm wrong. it wasn't more than 2 or 3 years ago that people were saying that java would never be fast enough, and i think that argument's been quashed. Adam