Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

transactions across DAO classes

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
rosshind
Asked:
rosshind
  • 4
  • 3
1 Solution
 
Tommy BraasCommented:
>> 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
 
CEHJCommented:
>>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
 
rosshindAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rosshindAuthor Commented:
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
 
CEHJCommented:
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
 
CEHJCommented:
This may throw an interesting light on your investigations:

http://jdocentral.com/

http://jdocentral.com/JDO_Commentary_CraigRussell_1.html
0
 
rosshindAuthor Commented:
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
 
CEHJCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now