在春天的petclinic设置hibernate.max_fetch_depth

时间:2014-11-06 22:26:25

标签: java spring hibernate spring-mvc jpa

我正在尝试使用spring petclinic应用程序,其完整代码为at this link。我想设置hibernate.max_fetch_depth=0,但是当我重新启动tomcat服务器并从eclipse重新启动应用程序时,我似乎无法使此设置生效。

这是a link to the directory that contains all the config files我应该在哪个配置文件中放置hibernate.max_fetch_depth=0设置,以及我应该使用哪种确切的语法?

我尝试将其放在business-config.xml

<property name="jpaProperties">
     <props>
        <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
        <prop key="hibernate.max_fetch_depth">0</prop>
    </props>
</property>  

我也试过把它放在data-access.properties

 hibernate.max_fetch_depth=0  

但这两种方法似乎都不起作用。

2 个答案:

答案 0 :(得分:1)

我创建了hibernate.properties文件并将其放在src/main/resources下。

添加以下条目到属性文件并重新启动服务器:

max_fetch_depth=3

从日志中我可以验证属性是否已在休眠配置中设置。

答案 1 :(得分:1)

我在GitHub中的一个测试中设置了它:

properties.put("hibernate.max_fetch_depth", "0");

然后我重新编写了SessionFactory类:

Integer maxFetchDepth = ConfigurationHelper.getInteger( AvailableSettings.MAX_FETCH_DEPTH, properties );
if ( maxFetchDepth != null ) {
    LOG.debugf( "Maximum outer join fetch depth: %s", maxFetchDepth );
}
settings.setMaximumFetchDepth( maxFetchDepth );

它完美无缺:

DEBUG [main]: o.h.c.SettingsFactory - Maximum outer join fetch depth: 0

尝试在persistence.xml中定义它:

<properties>
    <property name="hibernate.max_fetch_depth" value="0"/>
</properties>