spring-data-jpa creates an instance of JpaMetamodelMappingContext
, which maintains a metamodel of JPA entities, when @EnableJpaRepositories
is used.
We'd like to use the CrudRepository
features ( findOne
, delete
...) in conjunction with org.springframework.data.jpa.domain.Specifications<T>
. @Query
or the dynamically generated queries from method names are not needed.
Do we need the JpaMetamodelMappingContext
in this scenario?
(Reason: that context is rather huge in terms of heap space. If it's not needed for our use cases, we'd try to skip its creation.)
Thanks a lot!
Just for your reference, after one your running in live environment: It's possible to run spring-data's CrudRepository
and JpaRepository
without the JPA metamodel. Our Configuration
looks like:
@Configuration
@EnableJpaRepositories(basePackageClasses = Foo.class)
@ComponentScan(basePackageClasses = { Bar.class })
public class DomainConfiguration {
/**
* The returned factory will built a {@link JpaMetamodelMappingContext} without a JPA MetaModel.
*
* This could save a couple of hundres MBs of heap space, but may disable some of spring-data's features.
*
* @return factory bean for {@link JpaMetamodelMappingContext}.
*/
@Bean(name = BeanDefinitionNames.JPA_MAPPING_CONTEXT_BEAN_NAME)
public JpaMetamodelMappingContextFactoryBean jpaMetamodelMappingContextFactoryBean() {
JpaMetamodelMappingContextFactoryBean factory = new JpaMetamodelMappingContextFactoryBean();
return factory;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.