Structure application web problème de hiérarchie
-
02-10-2019 - |
Question
Voici une illustration de ma hiérarchie de projet
(source: yfrog.com )
Quand j'essaie de connecter mon fichier file_name.java hiberner je reçois ces erreurs
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)
le problème a quelque chose à voir avec mon hibernate.cfg.xml
... mais je suis incapable de le résoudre. Toutes les idées?
La solution
Je soupçonne que vous utilisez soit @Cacheable
ou @Cache
sur vos entités sans avoir le cache de second niveau activé, d'où le message d'erreur:
o.h.c.NoCachingEnabledException: Second-level cache is not enabled for usage ...
Vous avez besoin de quelque chose comme ça dans le hibernate.cfg.xml
d'utiliser le cache de second niveau (j'utilise EHCache en tant que fournisseur de cache ici):
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
Que vous avez vraiment besoin du cache de second niveau est une autre histoire.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow