[英]What's the purpose of JpaMetamodelMappingContext?
spring-data-jpa creates an instance of JpaMetamodelMappingContext
, which maintains a metamodel of JPA entities, when @EnableJpaRepositories
is used. 弹簧数据JPA创建的实例
JpaMetamodelMappingContext
,它保持JPA实体的元模型,当@EnableJpaRepositories
被使用。
We'd like to use the CrudRepository
features ( findOne
, delete
...) in conjunction with org.springframework.data.jpa.domain.Specifications<T>
. 我们希望将
CrudRepository
功能( findOne
, delete
...)与org.springframework.data.jpa.domain.Specifications<T>
结合使用。 @Query
or the dynamically generated queries from method names are not needed. @Query
或从方法名称动态生成的查询。
Do we need the JpaMetamodelMappingContext
in this scenario? 在这种情况下,我们需要
JpaMetamodelMappingContext
吗?
(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. 在现场环境中运行后,仅供参考:可以在没有JPA元模型的情况下运行spring-data的
CrudRepository
和JpaRepository
。 Our Configuration
looks like: 我们的
Configuration
如下:
@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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.