21
21
import javax .persistence .metamodel .ManagedType ;
22
22
import javax .persistence .metamodel .Metamodel ;
23
23
24
+ import org .springframework .beans .factory .DisposableBean ;
24
25
import org .springframework .data .jpa .provider .PersistenceProvider ;
25
26
import org .springframework .data .jpa .util .JpaMetamodel ;
26
27
import org .springframework .data .mapping .PersistentPropertyPaths ;
38
39
* @author Oliver Gierke
39
40
* @author Christoph Strobl
40
41
* @author Mark Paluch
42
+ * @author Sylvère Richard
41
43
* @since 1.3
42
44
*/
43
45
public class JpaMetamodelMappingContext
44
- extends AbstractMappingContext <JpaPersistentEntityImpl <?>, JpaPersistentProperty > {
46
+ extends AbstractMappingContext <JpaPersistentEntityImpl <?>, JpaPersistentProperty >
47
+ implements DisposableBean {
45
48
46
49
private final Metamodels models ;
47
50
private final PersistenceProvider persistenceProvider ;
@@ -90,7 +93,7 @@ protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
90
93
91
94
/**
92
95
* We customize the lookup of {@link PersistentPropertyPaths} by also traversing properties that are embeddables.
93
- *
96
+ *
94
97
* @see org.springframework.data.mapping.context.AbstractMappingContext#findPersistentPropertyPaths(java.lang.Class,
95
98
* java.util.function.Predicate)
96
99
*/
@@ -100,7 +103,7 @@ public <T> PersistentPropertyPaths<T, JpaPersistentProperty> findPersistentPrope
100
103
return doFindPersistentPropertyPaths (type , predicate , it -> it .isEmbeddable ());
101
104
}
102
105
103
- /*
106
+ /*
104
107
* (non-Javadoc)
105
108
* @see org.springframework.data.mapping.context.AbstractMappingContext#hasPersistentEntityFor(java.lang.Class)
106
109
*/
@@ -109,7 +112,16 @@ public boolean hasPersistentEntityFor(Class<?> type) {
109
112
return super .hasPersistentEntityFor (type ) || models .isMetamodelManagedType (type );
110
113
}
111
114
112
- /**
115
+ /*
116
+ * (non-Javadoc)
117
+ * @see org.springframework.beans.factory.DisposableBean#destroy()
118
+ */
119
+ @ Override
120
+ public void destroy () throws Exception {
121
+ JpaMetamodel .clearCache ();
122
+ }
123
+
124
+ /**
113
125
* A wrapper for a set of JPA {@link Metamodel} instances to simplify lookups of {@link JpaMetamodel} instances and
114
126
* managed type checks.
115
127
*
@@ -125,7 +137,7 @@ private Metamodels(Set<Metamodel> metamodels) {
125
137
126
138
/**
127
139
* Returns the {@link JpaMetamodel} for the given type.
128
- *
140
+ *
129
141
* @param type must not be {@literal null}.
130
142
* @return
131
143
*/
@@ -139,7 +151,7 @@ public JpaMetamodel getMetamodel(TypeInformation<?> type) {
139
151
140
152
/**
141
153
* Returns whether the given type is managed by one of the underlying {@link Metamodel} instances.
142
- *
154
+ *
143
155
* @param type must not be {@literal null}.
144
156
* @return
145
157
*/
@@ -149,7 +161,7 @@ public boolean isMetamodelManagedType(TypeInformation<?> type) {
149
161
150
162
/**
151
163
* Returns whether the given type is managed by one of the underlying {@link Metamodel} instances.
152
- *
164
+ *
153
165
* @param type must not be {@literal null}.
154
166
* @return
155
167
*/
0 commit comments