gpt4 book ai didi

java - Web应用程序结构层次问题

转载 作者:行者123 更新时间:2023-11-30 05:11:34 24 4
gpt4 key购买 nike

下面是我的项目层次结构的图示

project hierarchy
(来源:yfrog.com)

当我尝试将 file_name.java 文件连接到 hibernate 时,我收到这些错误

Exception in thread "main" org.hibernate.HibernateException: Could not instantiate cache implementation
at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:214)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
at net.pkg.dao.FirstExample.main(FirstExample.java:17)
Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
at org.hibernate.cache.NoCacheProvider.buildCache(NoCacheProvider.java:21)
at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:61)

问题与我的 hibernate.cfg.xml 有关...但我无法解决它。有什么想法吗?

最佳答案

我怀疑您在实体上使用 @Cacheable@Cache 而没有激活二级缓存,因此出现错误消息:

o.h.c.NoCachingEnabledException: Second-level cache is not enabled for usage ...

您需要在 hibernate.cfg.xml 中使用二级缓存(我在这里使用 EHCache 作为缓存提供程序):

<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>

您是否真的需要二级缓存是另一回事。

关于java - Web应用程序结构层次问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3183688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com