Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 191379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:20:11+00:00 2026-05-11T16:20:11+00:00

So I’ve got this generic DAO thing going on and at face value it

  • 0

So I’ve got this generic DAO thing going on and at face value it appears to be ok. It’s basically modeled after the CaveatEmptor sample application from the Hibernate guys.

On top of that I have a business layer…the guts of the application. It’s completely unaware of any specific DAO implementation.

Everything up to this point seems fine, until I start thinking about transactions. If transactions are left to the client to implement, then how in the world do I maintain the nice separation I’ve got going on between my layers? That is, I’m using Hibernate at the moment, and I don’t really feel much like adding hibernate-specific transactions to my business layer code.

I could create a simple transaction interface with begin, commit, and rollback methods and pass an implementation to my business layer…but…I’m not sure…

So here is the challenge: can you recommend a way for me to do this without using the word Spring (or EJB, or any other additional framework)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:20:11+00:00Added an answer on May 11, 2026 at 4:20 pm

    I remember that Martin Fowler advices to keep the control of the transaction in the business layer because transaction is a business problem. (If you design a BankAccount class, a transaction is part of the domain language).

    You can try to implement a TransactionScope as in .NET it works something like that

    using (TransactionScope ts = new TransactionScope())
    {
      ...
    }
    

    It’s the same thing as (not exactly but if you are a Java guy, it’s more explicit to you)

    TransactionScope scope = new TransactionScope();
    try
    {
     ...
     scope.Commit();
    }
    catch(Exception ex)
    {
      scope.Rollback();
      throw;
    }
    

    To decouple your business layer from any DAO technologies you can add a TransactionFactory in your domain language, which return a ITransactionScope (an interface) that you have defined with a Commit and Rollback methods. This way your domain layer is not bound to your DAO layer, only a concrete implementation of TransactionFactory is.

    ITransactionScope scope = transactionFactory.CreateTransaction();
    try
    {
     ...
     scope.Commit();
    }
    catch(Exception ex)
    {
      scope.Rollback();
      throw;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer CTRL+SHIFT+F and change Look-in to be c:\path\to\your\code. Edit: Or, from… May 12, 2026 at 12:21 am
  • Editorial Team
    Editorial Team added an answer This page is from the Google Maps API documentation, and… May 12, 2026 at 12:21 am
  • Editorial Team
    Editorial Team added an answer Since it is marked as inherited, there isn't much you… May 12, 2026 at 12:21 am

Related Questions

So I'm getting a new job working with databases (Microsoft SQL Server to be
So I have a Sybase stored proc that takes 1 parameter that's a comma
So I'm embarking on an ASP.NET MVC project and while the experience has been
So I've got a JPanel implementing MouseListener and MouseMotionListener : import javax.swing.*; import java.awt.*;
So I wrote some perl that would parse results returned from the Amazon Web

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.