Solved

transactions across DAO classes

Posted on 2004-03-25
8
220 Views
Last Modified: 2010-03-31
Hi,

I have an e-commerce application which has all kinds of data access objects which roughly relate to tables in hte database.

For example I have a customer table and an address table

These relate to my customer and Address objects which have CustomerDAO and AddressDAO objects associated with them.  Fine so far.

Each of the methods in my DAO objects open a connection to the database, do their thing (like an insert or an update) then release the connection.

The problem comes when I need to encapsulate the insertion of a customer and the insertion of an address into a transaction.  A transaction can not be done over more than one continuous connection (I think).  Should I be passing a connection object to these methods explicitly and only opening a new connection if it is null?

How do you do it?
Would EJBs help?
0
Comment
Question by:rosshind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10679297
>> How do you do it?
I assume that the Customer HAS-A Address, in which case, start a transaction, you insert/update the customer first, hand over control to the Address passing along the connection in some form (setConnection() perhaps, to keep it simple), and have the Address insert/update itself.

>> Would EJBs help?
Container managed persistence, if used, certainly would.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10679375
>>A transaction can not be done over more than one continuous connection (I think).  

The boundaries of a transaction are not really related to the connection. You mention EJBs. There is a case in point: not only are transactions not connection-related, they are not even process-related in that they can be distributed across process and even network boundaries.

It's the transaction object that would have to be passed around - sounds like you're getting into some farily complex wheel-reinvention here [unless you're now using third-party DAO] ;-)
0
 

Author Comment

by:rosshind
ID: 10685385
Thanks for your help,

I'm not sure how any third party technology could help.  Each of my DAO objcets is a custom object, I might want some ot work slightly differently to others.  

What kind of third party technology do you mean CJ?  What am I programming here  which has already been done for me by someone else?

Would you be using a third party DAO?

What are the fundamental differences between EJB and what I am doing? Can you referr me to a tutorial about the fundamentals of EJBs?  As you know, I'm not new to programming or to complex e-commerce sites,  but I've only really been doing JAVA for around 3 weeks ...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rosshind
ID: 10685556
From the sounds of it EJBs are the way to go.  I could continue my program with normal beans, but I recon it might work out more difficult and messy in the long run.  I may be better off learning EJBs  now before completing the first version of the software..  What do you think?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 10686047
It's a possibility, although i think as we've said before (or at least 'ive said it ;-)) EJB is not really an 'escape route' out of persistence complexities. All you need seemingly is a persistence layer that supports transactions and O-R mapping by the sounds of things. That is already present in certain free packages, none of which i've used incidentally.

Having said that about EJBs, if you can take what will be a steep learning curve, these services, along with a host of other services are present as standard in EJB.

If you want to use EJB, you'll need an application server and unless you've got very deep pockets, we're talking about JBoss practically, which is free. The only slight problem is that free documentation is very thin on the ground and you probably need to pay for it. This is not highly priced though.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10696588
This may throw an interesting light on your investigations:

http://jdocentral.com/

http://jdocentral.com/JDO_Commentary_CraigRussell_1.html
0
 

Author Comment

by:rosshind
ID: 10697859
I've bought a dell server which is to be dedicated to this venture.  My pockets are empty now.

I've been on a steep learning curve for about 4 weeks learning JAVA.  I figure another week or two for EJB will be worth it in hte long term so that the first version can be using the best technology for the venture.

I've gone out and bought Enterprise JavaBeans by O'Reilly to help me get up to speed on this.  Thanks for your help.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10698090
8-)

>>...Enterprise JavaBeans by O'Reilly ...

Still keep meaning to do the JBoss exercises from that but haven't got round to it yet ;-)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Way to decrease size of apk file 9 104
login jsp example 24 85
project copy paste issue 1 61
glassfish admin console 1 17
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question