2525import org .springframework .data .mapping .PersistentEntity ;
2626import org .springframework .data .repository .CrudRepository ;
2727import org .springframework .data .util .Streamable ;
28+ import org .springframework .transaction .annotation .Transactional ;
2829
2930/**
3031 * @author Jens Schauder
3132 * @author Oliver Gierke
3233 */
3334@ RequiredArgsConstructor
35+ @ Transactional (readOnly = true )
3436public class SimpleJdbcRepository <T , ID > implements CrudRepository <T , ID > {
3537
3638 private final @ NonNull
@@ -43,6 +45,7 @@ public class SimpleJdbcRepository<T, ID> implements CrudRepository<T, ID> {
4345 * @see org.springframework.data.repository.CrudRepository#save(S)
4446 */
4547 @ Override
48+ @ Transactional
4649 public <S extends T > S save (S instance ) {
4750 return entityOperations .save (instance );
4851 }
@@ -52,6 +55,7 @@ public <S extends T> S save(S instance) {
5255 * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
5356 */
5457 @ Override
58+ @ Transactional
5559 public <S extends T > Iterable <S > saveAll (Iterable <S > entities ) {
5660
5761 return Streamable .of (entities ).stream () //
@@ -109,6 +113,7 @@ public long count() {
109113 * @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable)
110114 */
111115 @ Override
116+ @ Transactional
112117 public void deleteById (ID id ) {
113118 entityOperations .deleteById (id , entity .getType ());
114119 }
@@ -118,6 +123,7 @@ public void deleteById(ID id) {
118123 * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Object)
119124 */
120125 @ Override
126+ @ Transactional
121127 public void delete (T instance ) {
122128 entityOperations .delete (instance , entity .getType ());
123129 }
@@ -127,12 +133,14 @@ public void delete(T instance) {
127133 * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable)
128134 */
129135 @ Override
136+ @ Transactional
130137 @ SuppressWarnings ("unchecked" )
131138 public void deleteAll (Iterable <? extends T > entities ) {
132139 entities .forEach (it -> entityOperations .delete (it , (Class <T >) it .getClass ()));
133140 }
134141
135142 @ Override
143+ @ Transactional
136144 public void deleteAll () {
137145 entityOperations .deleteAll (entity .getType ());
138146 }
0 commit comments