【问题标题】:setting hibernate.max_fetch_depth in spring petclinic在 spring petclinic 中设置 hibernate.max_fetch_depth
【发布时间】:2015-01-03 14:45:20
【问题描述】:

我正在尝试使用 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  

但这两种方法似乎都行不通。

【问题讨论】:

    标签: java spring hibernate spring-mvc jpa


    【解决方案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>   
    

    【讨论】:

    • 您是否设法找到为什么它一开始就不起作用?
    • 过度继承导致问题。您在对根本问题的回答中说明了这一点。我最终扁平化了部分架构以减少连接中包含的表的数量。感谢您的跟进。
    • 我还有另一个休眠问题。你也愿意帮助我吗?这是链接:stackoverflow.com/questions/29640195/…
    【解决方案2】:

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

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

    max_fetch_depth=3

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 2013-04-20
      • 2013-09-09
      • 2019-03-27
      • 1970-01-01
      相关资源
      最近更新 更多