给出以下设置:
spring.jpa.open-in-view=true
,spring.jpa.properties.hibernate.hbm2ddl.auto=none
,spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
,spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
启用跟踪时,我注意到hibernate会在启动时打开n
个会话。
n
数字奇怪等于@org.springframework.transaction.annotation.Transactional(readOnly=true)
注释的方法数。
我还注意到负责打开这些会话的组件是org.springframework.orm.jpa.SharedEntityManagerCreator
,正好是以下代码部分:
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//...
boolean isNewEm = false;
if (target == null) {
logger.debug("Creating new EntityManager for shared EntityManager invocation");
target = (!CollectionUtils.isEmpty(this.properties) ?
this.targetFactory.createEntityManager(this.properties) :
this.targetFactory.createEntityManager());
isNewEm = true;
}
//...
}
这里有一个link截图,显示了被代理的方法。
话虽如此,我的问题是:
是否有任何对此行为的解释,因为我希望在应用程序完全启动之前不会打开任何会话,或者在启动期间需要数据操作操作(加载架构)(这是不是我的情况)...