2014-11-06 35 views
1

我正在试验春季宠物诊所的应用程序,它的完整代码是at this link。我想设置hibernate.max_fetch_depth=0,但似乎无法让我的设置在我重新启动tomcat服务器并从eclipse重新启动应用程序时生效。设置hibernate.max_fetch_depth在春天petclinic

这是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 

但无论是做法似乎工作。

回答

1

我把它在我的测试之一GitHub

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

然后我debbuged了一个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> 
+0

你有没有设法找到它为什么不起作用? – 2014-11-17 20:45:06

+1

过度的继承导致了这个问题。你在回答根本问题时已经说明了这一点。我最终将模式的一部分展平以减少包含在连接中的表的数量。感谢您的跟进。 – CodeMed 2014-11-17 23:20:13

+0

我有另一个休眠问题。你愿意帮助我吗?这里是链接:http://stackoverflow.com/questions/29640195/unidirectional-many-to-one-relationship-with-inheritance – CodeMed 2015-04-15 01:52:00

1

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

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

max_fetch_depth=3

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

+0

+1并感谢您花时间回答。 – CodeMed 2014-11-17 20:41:14