/
HibernateRepository.java
181 lines (161 loc) · 5.98 KB
/
HibernateRepository.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package com.vladmihalcea.spring.repository;
import java.util.List;
/**
* The {@code HibernateRepository} fixes the problems that the default Spring Data {@code JpaRepository}
* suffers from.
* <p>
* For more details about how to use it, check out <a href=
* "https://vladmihalcea.com/best-spring-data-jparepository/">this article</a>.
*
* @author Vlad Mihalcea
* @version 2.17.0
*/
public interface HibernateRepository<T> {
/**
* The findAll method is a terrible Anti-Pattern.
* <p>
* For more details about why you should not use the {@code findAll} method by default,
* check out <a href="https://vladmihalcea.com/spring-data-findall-anti-pattern/">this article</a>.
*
* @return all the records from the database table this entity is mapped to
*/
@Deprecated
List<T> findAll();
//The save methods will trigger an UnsupportedOperationException
/**
* The save method should be avoided.
* <p>
* For more details about how to use it, check out <a href="https://vladmihalcea.com/best-spring-data-jparepository/">this article</a>.
*/
@Deprecated
<S extends T> S save(S entity);
/**
* The save method should be avoided.
* <p>
* For more details about how to use it, check out <a href="https://vladmihalcea.com/best-spring-data-jparepository/">this article</a>.
*/
@Deprecated
<S extends T> List<S> saveAll(Iterable<S> entities);
/**
* The saveAndFlush method should be avoided.
* <p>
* For more details about how to use it, check out <a href="https://vladmihalcea.com/best-spring-data-jparepository/">this article</a>.
*/
@Deprecated
<S extends T> S saveAndFlush(S entity);
/**
* The saveAllAndFlush method should be avoided.
* <p>
* For more details about how to use it, check out <a href="https://vladmihalcea.com/best-spring-data-jparepository/">this article</a>.
*/
@Deprecated
<S extends T> List<S> saveAllAndFlush(Iterable<S> entities);
/**
* The persist method allows you to pass the provided entity to the {@code persist} method of the
* underlying JPA {@code EntityManager}.
*
* @param entity entity to persist
* @param <S> entity type
* @return entity
*/
<S extends T> S persist(S entity);
/**
* The persistAndFlush method allows you to pass the provided entity to the {@code persist} method of the
* underlying JPA {@code EntityManager} and call {@code flush} afterwards.
*
* @param entity entity to persist
* @param <S> entity type
* @return entity
*/
<S extends T> S persistAndFlush(S entity);
/**
* The persistAll method allows you to pass the provided entities to the {@code persist} method of the
* underlying JPA {@code EntityManager}.
*
* @param entities entities to persist
* @param <S> entity type
* @return entities
*/
<S extends T> List<S> persistAll(Iterable<S> entities);
/**
* The persistAll method allows you to pass the provided entities to the {@code persist} method of the
* underlying JPA {@code EntityManager} and call {@code flush} afterwards.
*
* @param entities entities to persist
* @param <S> entity type
* @return entities
*/
<S extends T> List<S> peristAllAndFlush(Iterable<S> entities);
/**
* The persist method allows you to pass the provided entity to the {@code merge} method of the
* underlying JPA {@code EntityManager}.
*
* @param entity entity to merge
* @param <S> entity type
* @return entity
*/
<S extends T> S merge(S entity);
/**
* The mergeAndFlush method allows you to pass the provided entity to the {@code merge} method of the
* underlying JPA {@code EntityManager} and call {@code flush} afterwards.
*
* @param entity entity to merge
* @param <S> entity type
* @return entity
*/
<S extends T> S mergeAndFlush(S entity);
/**
* The mergeAll method allows you to pass the provided entities to the {@code merge} method of the
* underlying JPA {@code EntityManager}.
*
* @param entities entities to merge
* @param <S> entity type
* @return entities
*/
<S extends T> List<S> mergeAll(Iterable<S> entities);
/**
* The mergeAllAndFlush method allows you to pass the provided entities to the {@code merge} method of the
* underlying JPA {@code EntityManager} and call {@code flush} afterwards.
*
* @param entities entities to persist
* @param <S> entity type
* @return entities
*/
<S extends T> List<S> mergeAllAndFlush(Iterable<S> entities);
/**
* The update method allows you to pass the provided entity to the {@code update} method of the
* underlying JPA {@code EntityManager}.
*
* @param entity entity to update
* @param <S> entity type
* @return entity
*/
<S extends T> S update(S entity);
/**
* The updateAndFlush method allows you to pass the provided entity to the {@code update} method of the
* underlying JPA {@code EntityManager} and call {@code flush} afterwards.
*
* @param entity entity to update
* @param <S> entity type
* @return entity
*/
<S extends T> S updateAndFlush(S entity);
/**
* The updateAll method allows you to pass the provided entities to the {@code update} method of the
* underlying JPA {@code EntityManager}.
*
* @param entities entities to update
* @param <S> entity type
* @return entities
*/
<S extends T> List<S> updateAll(Iterable<S> entities);
/**
* The updateAllAndFlush method allows you to pass the provided entities to the {@code update} method of the
* underlying JPA {@code EntityManager} and call {@code flush} afterwards.
*
* @param entities entities to update
* @param <S> entity type
* @return entities
*/
<S extends T> List<S> updateAllAndFlush(Iterable<S> entities);
}