2010年11月5日星期五

Re: [fw-db] Nasted transactions

On Nov 4, 2010, at 11:52 PM, umpirsky wrote:

> What are the best practices for organizing transactions in zf app?

Don't manage transactions in models. Transaction state is scoped to
the database connection. If you try to encapsulate transaction state
within model objects, you create a type of coupling between your models.

The best solution is to manage transactions in a service layer. This
is how Hibernate-based applications usually do it, for example. In
ZF, your Controller actions act as a rudimentary service layer. So
start the transaction in the Controller action and commit or rollback
depending on whether *all* model functions succeed or fail.

The other alternative is to create a separate database connection for
each model that needs to manage its own transaction state. But I
don't recommend this.

Regards,
Bill Karwin

没有评论: