Solved

transactions across DAO classes

Posted on 2004-03-25
8
219 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap bin 2 40
iterator/ListIterator approach 17 39
Problem to Alipay 10 43
learn programming 8 39
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

856 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