[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (HHH-7101) NPE when trying to create EntityManagerFactory
Bryan Varner (JIRA)
noreply at atlassian.com
Mon Apr 16 14:30:48 EDT 2012
[ https://hibernate.onjira.com/browse/HHH-7101?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46312#comment-46312 ]
Bryan Varner edited comment on HHH-7101 at 4/16/12 1:29 PM:
------------------------------------------------------------
I ran into this problem today, while testing an upgrade from 3.6.10.Final to 4.1.2.Final
I've tracked down what I believe is the underlying issue, and would really appreciate if someone from the project would take a few minutes to verify....
In AnnotationBinder.java:1042, it creates / locates a CacheRegionFactory. The code being invoked in SettingsFactory is littered with "//todo remove" type comments.
This block ends up returning an instance of NoCachingRegionFactory. This makes sense, since there is no 'hibernate.cache.region.factory_class' specified. The problem is, the code changed in...
CacheConcurrencyStrategy.java:52. This used to be a null-safe series of if's, but has been changed to a switch(), which is now throwing NPE when invoked on the default value of 'null' returned by NoCachingRegionFactory.getDefaultAccessType() on line 59.
I suppose the best (most correct) resolution is a null-check before the switch in CacheConcurrencyStrategy.java.
In the mean-time, a workaround is to correctly configure your second-level cache, by adding...
<property name="hibernate.cache.region.factory_class" value="_provider class name_"/> in your persistence.xml
If you use ehcache, make sure you include hibernate-ehcache-4.1.2.Final.jar in your classpath, and use 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' as your provider class name. The older provider name will try to load the old ehcache classes, and you'll get ClassNotFound exceptions.
was (Author: bvarner):
I ran into this problem today, while testing an upgrade from 3.6.10.Final to 4.1.2.Final
I've tracked down what I believe is the underlying issue, and would really appreciate if someone from the project would take a few minutes to verify....
In AnnotationBinder.java:1042, it creates / locates a CacheRegionFactory. The code being invoked in SettingsFactory is littered with "//todo remove" type comments.
This block ends up returning an instance of NoCachingRegionFactory. This makes sense, since there is no 'hibernate.cache.region.factory_class' specified. The problem is, the code changed in...
CacheConcurrencyStrategy.java:52. This used to be a null-safe series of if's, but has been changed to a switch(), which is now throwing NPE when invoked on the default value of 'null' returned by NoCachingRegionFactory.getDefaultAccessType() on line 59.
I suppose the best (most correct) resolution is a null-check before the switch in CacheConcurrencyStrategy.java.
In the mean-time, a workaround is to correctly configure your second-level cache, by adding...
<property name="hibernate.cache.region.factory_class" value="-provider class name-"/> in your persistence.xml
If you use ehcache, make sure you include hibernate-ehcache-4.1.2.Final.jar in your classpath, and use 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' as your provider class name. The older provider name will try to load the old ehcache classes, and you'll get ClassNotFound exceptions.
> NPE when trying to create EntityManagerFactory
> ----------------------------------------------
>
> Key: HHH-7101
> URL: https://hibernate.onjira.com/browse/HHH-7101
> Project: Hibernate ORM
> Issue Type: Bug
> Components: core
> Affects Versions: 4.1.0
> Environment: hibernate-jpa-2.0-api:1.0.1-Final; hibernate-core:4.1.0.Final; hibernate-entitymanager:4.1.0.Final
> Reporter: Michael Nascimento Santos
> Labels: hibernate, jpa2
> Attachments: npe4cacheable.zip
>
>
> A NPE is thrown for a simple pure JPA entity annotated with @Cacheable as follows:
> @Entity
> @Cacheable
> public class SampleEntity {
> @Id
> @GeneratedValue(strategy=GenerationType.AUTO)
> private Long id;
> }
> When Persistence.createEntityManagerFactory(String) is called and such entity is part of the persistence unit, this produces:
> java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
> at java.lang.Thread.run(Thread.java:662)
> Caused by: java.lang.NullPointerException
> at org.hibernate.annotations.CacheConcurrencyStrategy.fromAccessType(CacheConcurrencyStrategy.java:52)
> at org.hibernate.cfg.AnnotationBinder.determineCacheConcurrencyStrategy(AnnotationBinder.java:1044)
> at org.hibernate.cfg.AnnotationBinder.buildCacheMock(AnnotationBinder.java:1011)
> at org.hibernate.cfg.AnnotationBinder.determineCacheSettings(AnnotationBinder.java:968)
> at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:577)
> at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3431)
> at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3385)
> at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1337)
> at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1727)
> at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:88)
> at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
> at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
> at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
> at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
> at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
> at org.hibernate.test.npe4cacheable.SampleEntity.main(SampleEntity.java:18)
> ... 6 more
> Hibernate should either choose some sensible default strategy or produce a clear message indicating the need to set one manually.
> Attached is a Maven-powered sample with Derby that can be executed with exec:java .
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list