Skip to Main Content
Spring: A Developer's Notebook
book

Spring: A Developer's Notebook

by Bruce Tate, Justin Gehtland
April 2005
Intermediate to advanced content levelIntermediate to advanced
216 pages
4h 44m
English
O'Reilly Media, Inc.
Content preview from Spring: A Developer's Notebook

Configuring Simple Transactions

Now, you'll see the most useful type of transaction support: declarative transactions. It's time to go back and explain the configuration of the transactions on your façade. In Chapter 4, you configured the transactions without explanation. It's time to go back and fill in the holes.

Declarative transactions are perhaps the most important feature of EJB session beans. Many developers decide not to use EJB at all when they discover that you can in fact use declarative transactions without sacrificing your first-born child.

You will implement declarative transactions without ever touching the code. You only need to change the context. Just like the examples in the previous chapter, you will configure an interceptor. The interceptor defines the methods to be marked as transactional and defines their expected behavior. Some of the methods will use full transaction propagation, and some will use a lighter-weight, read-only propagation (Example 7-3).

Example 7-3. RentABike-servlet.xml

<bean name="transactionInterceptor" class="org.springframework. transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"> <ref local="transactionManager"/> </property> <property name="transactionAttributeSource"> <value> com.springbook.RentABike.transferReservation= PROPAGATION_REQUIRED,-ReservationTransferException com.springbook.RentABike.save*=PROPAGATION_REQUIRED com.springbook.RentABike.*=PROPAGATION_REQUIRED,readOnly </value> </property> </bean> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaBeans Unleashed

JavaBeans Unleashed

Dr. Donald Doherty, Rick Leinecker
Beginning Spring

Beginning Spring

Mert Caliskan, Kenan Sevindik, Rod Johnson, Jürgen Höller
Hibernate Search in Action

Hibernate Search in Action

Emmanuel Bernard, John Griffin

Publisher Resources

ISBN: 0596009100Supplemental ContentErrata Page