@@ -67,7 +67,8 @@ public JpaMetamodelMappingContext(Set<Metamodel> models) {
6767 */
6868 @ Override
6969 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 ));
7172 }
7273
7374 /*
@@ -91,17 +92,17 @@ protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
9192
9293 /**
9394 * We customize the lookup of {@link PersistentPropertyPaths} by also traversing properties that are embeddables.
94- *
95+ *
9596 * @see org.springframework.data.mapping.context.AbstractMappingContext#findPersistentPropertyPaths(java.lang.Class,
9697 * java.util.function.Predicate)
9798 */
9899 @ Override
99100 public <T > PersistentPropertyPaths <T , JpaPersistentProperty > findPersistentPropertyPaths (Class <T > type ,
100101 Predicate <? super JpaPersistentProperty > predicate ) {
101- return doFindPersistentPropertyPaths (type , predicate , it -> it . isEmbeddable () );
102+ return doFindPersistentPropertyPaths (type , predicate , JpaPersistentProperty :: isEmbeddable );
102103 }
103104
104- /*
105+ /*
105106 * (non-Javadoc)
106107 * @see org.springframework.data.mapping.context.AbstractMappingContext#hasPersistentEntityFor(java.lang.Class)
107108 */
@@ -126,7 +127,7 @@ private Metamodels(Set<Metamodel> metamodels) {
126127
127128 /**
128129 * Returns the {@link JpaMetamodel} for the given type.
129- *
130+ *
130131 * @param type must not be {@literal null}.
131132 * @return
132133 */
@@ -138,9 +139,29 @@ public JpaMetamodel getMetamodel(TypeInformation<?> type) {
138139 return metamodel == null ? null : JpaMetamodel .of (metamodel );
139140 }
140141
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+
141162 /**
142163 * Returns whether the given type is managed by one of the underlying {@link Metamodel} instances.
143- *
164+ *
144165 * @param type must not be {@literal null}.
145166 * @return
146167 */
@@ -150,7 +171,7 @@ public boolean isMetamodelManagedType(TypeInformation<?> type) {
150171
151172 /**
152173 * Returns whether the given type is managed by one of the underlying {@link Metamodel} instances.
153- *
174+ *
154175 * @param type must not be {@literal null}.
155176 * @return
156177 */
0 commit comments