This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Best Practice for sharing db transaction across DAO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Best Practice for sharing db transaction across DAO" Watch "Best Practice for sharing db transaction across DAO" New topic
Author

Best Practice for sharing db transaction across DAO

Scott Huffman
Greenhorn

Joined: May 14, 2010
Posts: 3
Picture this:

I received a SalesLead that has several SalesLeadFields. I want to save the SalesLead, get it's generated id and then save the SalesLeadFields with that generated id as the foreign key.

You would expect to have a SalesLeadDAO and a SalesLeadFieldDAO. How do I ensure all of the inserts occur within the same transaction? If any insert fails I want the whole thing to rollback.

I'm also running in JBOSS with a datasource in JNDI wanting to use SpringJdbc to manage the datasource and bubbling up to Stripes as the framework.

Am I crazy? Is there a best practice?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Scott,
You would use Spring to manage the transactions. The DAOs would be within that transaction.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
 
subject: Best Practice for sharing db transaction across DAO
 
Similar Threads
mysql connectivity failure
Struts2 Save and Get updated List?
Hibernate and XA datasource
JAAS + JBOSS 5.1 - getting exception while trying perform authentication
Hibernate Mapping- composite id (pk+ foreign key)