Where does the @Transactional annotation belong?

Thomas Einwaller picture Thomas Einwaller · Jul 3, 2009 · Viewed 245.5k times · Source

Should you place the @Transactional in the DAO classes and/or their methods or is it better to annotate the Service classes which are calling using the DAO objects? Or does it make sense to annotate both "layers"?

Answer

duffymo picture duffymo · Jul 3, 2009

I think transactions belong on the Service layer. It's the one that knows about units of work and use cases. It's the right answer if you have several DAOs injected into a Service that need to work together in a single transaction.