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"?
Java – Where does the @Transactional annotation belong
annotationsdaojavaspringtransactions
Related Topic
- Java – How does the Java ‘for each’ loop work
- Java – Fastest way to determine if an integer’s square root is an integer
- Java – Comparing Java enum members: == or equals()
- Spring – Where should “@Transactional” be placed Service Layer or DAO
- Java – Which @NotNull Java annotation should I use
- Java – What’s the difference between @Component, @Repository & @Service annotations in Spring
- Java – What does “Could not find or load main class” mean
Best Answer
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.