Example usage for org.springframework.data.jpa.mapping JpaMetamodelMappingContext JpaMetamodelMappingContext

List of usage examples for org.springframework.data.jpa.mapping JpaMetamodelMappingContext JpaMetamodelMappingContext

Introduction

In this page you can find the example usage for org.springframework.data.jpa.mapping JpaMetamodelMappingContext JpaMetamodelMappingContext.

Prototype

public JpaMetamodelMappingContext(Set<Metamodel> models) 

Source Link

Document

Creates a new JPA Metamodel based MappingContext .

Usage

From source file:org.lightadmin.core.config.bootstrap.JpaMetamodelMappingContextFactoryBean.java

@Override
protected JpaMetamodelMappingContext createInstance() throws Exception {
    Metamodel metamodel = entityManager.getMetamodel();

    Set<ManagedType<?>> managedTypes = metamodel.getManagedTypes();
    Set<Class<?>> entitySources = new HashSet<Class<?>>(managedTypes.size());

    for (ManagedType<?> type : managedTypes) {

        Class<?> javaType = type.getJavaType();

        if (javaType != null) {
            entitySources.add(javaType);
        }/*from   ww  w. j  a  v  a  2 s .  com*/
    }

    Set<Metamodel> metaModelSet = new HashSet<>(Collections.singletonList(metamodel));
    JpaMetamodelMappingContext context = new JpaMetamodelMappingContext(metaModelSet);
    context.setInitialEntitySet(entitySources);
    context.initialize();

    return context;
}