@@ -67,7 +67,8 @@ public JpaMetamodelMappingContext(Set<Metamodel> models) {
67
67
*/
68
68
@ Override
69
69
protected <T > JpaPersistentEntityImpl <?> createPersistentEntity (TypeInformation <T > typeInformation ) {
70
- return new JpaPersistentEntityImpl <T >(typeInformation , persistenceProvider , models .getMetamodel (typeInformation ));
70
+ return new JpaPersistentEntityImpl <>(typeInformation , persistenceProvider ,
71
+ models .getRequiredMetamodel (typeInformation ));
71
72
}
72
73
73
74
/*
@@ -91,17 +92,17 @@ protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
91
92
92
93
/**
93
94
* We customize the lookup of {@link PersistentPropertyPaths} by also traversing properties that are embeddables.
94
- *
95
+ *
95
96
* @see org.springframework.data.mapping.context.AbstractMappingContext#findPersistentPropertyPaths(java.lang.Class,
96
97
* java.util.function.Predicate)
97
98
*/
98
99
@ Override
99
100
public <T > PersistentPropertyPaths <T , JpaPersistentProperty > findPersistentPropertyPaths (Class <T > type ,
100
101
Predicate <? super JpaPersistentProperty > predicate ) {
101
- return doFindPersistentPropertyPaths (type , predicate , it -> it . isEmbeddable () );
102
+ return doFindPersistentPropertyPaths (type , predicate , JpaPersistentProperty :: isEmbeddable );
102
103
}
103
104
104
- /*
105
+ /*
105
106
* (non-Javadoc)
106
107
* @see org.springframework.data.mapping.context.AbstractMappingContext#hasPersistentEntityFor(java.lang.Class)
107
108
*/
@@ -126,7 +127,7 @@ private Metamodels(Set<Metamodel> metamodels) {
126
127
127
128
/**
128
129
* Returns the {@link JpaMetamodel} for the given type.
129
- *
130
+ *
130
131
* @param type must not be {@literal null}.
131
132
* @return
132
133
*/
@@ -138,9 +139,29 @@ public JpaMetamodel getMetamodel(TypeInformation<?> type) {
138
139
return metamodel == null ? null : JpaMetamodel .of (metamodel );
139
140
}
140
141
142
+ /**
143
+ * Returns the required {@link JpaMetamodel} for the given type or throw {@link IllegalArgumentException} if the
144
+ * {@code type} is not JPA-managed.
145
+ *
146
+ * @param type must not be {@literal null}.
147
+ * @return
148
+ * @throws IllegalArgumentException if {@code type} is not JPA-managed.
149
+ * @since 2.6.1
150
+ */
151
+ public JpaMetamodel getRequiredMetamodel (TypeInformation <?> type ) {
152
+
153
+ JpaMetamodel metamodel = getMetamodel (type );
154
+
155
+ if (metamodel == null ) {
156
+ throw new IllegalArgumentException (String .format ("Required JpaMetamodel not found for %s!" , type ));
157
+ }
158
+
159
+ return metamodel ;
160
+ }
161
+
141
162
/**
142
163
* Returns whether the given type is managed by one of the underlying {@link Metamodel} instances.
143
- *
164
+ *
144
165
* @param type must not be {@literal null}.
145
166
* @return
146
167
*/
@@ -150,7 +171,7 @@ public boolean isMetamodelManagedType(TypeInformation<?> type) {
150
171
151
172
/**
152
173
* Returns whether the given type is managed by one of the underlying {@link Metamodel} instances.
153
- *
174
+ *
154
175
* @param type must not be {@literal null}.
155
176
* @return
156
177
*/
0 commit comments