25
25
import org .springframework .data .mapping .PersistentEntity ;
26
26
import org .springframework .data .repository .CrudRepository ;
27
27
import org .springframework .data .util .Streamable ;
28
+ import org .springframework .transaction .annotation .Transactional ;
28
29
29
30
/**
30
31
* @author Jens Schauder
31
32
* @author Oliver Gierke
32
33
*/
33
34
@ RequiredArgsConstructor
35
+ @ Transactional (readOnly = true )
34
36
public class SimpleJdbcRepository <T , ID > implements CrudRepository <T , ID > {
35
37
36
38
private final @ NonNull
@@ -43,6 +45,7 @@ public class SimpleJdbcRepository<T, ID> implements CrudRepository<T, ID> {
43
45
* @see org.springframework.data.repository.CrudRepository#save(S)
44
46
*/
45
47
@ Override
48
+ @ Transactional
46
49
public <S extends T > S save (S instance ) {
47
50
return entityOperations .save (instance );
48
51
}
@@ -52,6 +55,7 @@ public <S extends T> S save(S instance) {
52
55
* @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
53
56
*/
54
57
@ Override
58
+ @ Transactional
55
59
public <S extends T > Iterable <S > saveAll (Iterable <S > entities ) {
56
60
57
61
return Streamable .of (entities ).stream () //
@@ -109,6 +113,7 @@ public long count() {
109
113
* @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable)
110
114
*/
111
115
@ Override
116
+ @ Transactional
112
117
public void deleteById (ID id ) {
113
118
entityOperations .deleteById (id , entity .getType ());
114
119
}
@@ -118,6 +123,7 @@ public void deleteById(ID id) {
118
123
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Object)
119
124
*/
120
125
@ Override
126
+ @ Transactional
121
127
public void delete (T instance ) {
122
128
entityOperations .delete (instance , entity .getType ());
123
129
}
@@ -127,12 +133,14 @@ public void delete(T instance) {
127
133
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable)
128
134
*/
129
135
@ Override
136
+ @ Transactional
130
137
@ SuppressWarnings ("unchecked" )
131
138
public void deleteAll (Iterable <? extends T > entities ) {
132
139
entities .forEach (it -> entityOperations .delete (it , (Class <T >) it .getClass ()));
133
140
}
134
141
135
142
@ Override
143
+ @ Transactional
136
144
public void deleteAll () {
137
145
entityOperations .deleteAll (entity .getType ());
138
146
}
0 commit comments