/
HibernateRepository.java
67 lines (42 loc) · 1.74 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
package com.vladmihalcea.spring.repository;
import java.util.List;
/**
* The {@code HibernateRepository} fixes the problems that the default Spring Data {@code JpaRepository}
* suffers from.
*
* 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 will trigger an UnsupportedOperationException
@Deprecated
List<T> findAll();
//The save methods will trigger an UnsupportedOperationException
@Deprecated
<S extends T> S save(S entity);
@Deprecated
<S extends T> List<S> saveAll(Iterable<S> entities);
@Deprecated
<S extends T> S saveAndFlush(S entity);
@Deprecated
<S extends T> List<S> saveAllAndFlush(Iterable<S> entities);
//The persist methods are meant to save newly created entities
<S extends T> S persist(S entity);
<S extends T> S persistAndFlush(S entity);
<S extends T> List<S> persistAll(Iterable<S> entities);
<S extends T> List<S> peristAllAndFlush(Iterable<S> entities);
//The merge methods are meant to propagate detached entity state changes
//if they are really needed
<S extends T> S merge(S entity);
<S extends T> S mergeAndFlush(S entity);
<S extends T> List<S> mergeAll(Iterable<S> entities);
<S extends T> List<S> mergeAllAndFlush(Iterable<S> entities);
//The update methods are meant to force the detached entity state changes
<S extends T> S update(S entity);
<S extends T> S updateAndFlush(S entity);
<S extends T> List<S> updateAll(Iterable<S> entities);
<S extends T> List<S> updateAllAndFlush(Iterable<S> entities);
}