-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: EntityManager and Tomcat: NullPointerException
PostPosted: Mon Jan 30, 2006 3:19 am 
Regular
Regular

Joined: Tue May 24, 2005 9:06 am
Posts: 64
Hibernate version: 3.1.1
Hibernate Annotations version: 3.1beta8
Hibernate EntityManager version: 3.1beta6

Tomcat version: 5.5.15
PostgreSQL version: 8.1.2

In my class DbUtil (aka HibernateUtil) I have this static initializer:
static {
try {
emf = Persistence.createEntityManagerFactory("hska");
}
catch (Throwable e) {
log.fatal("Initial EntityManagerFactory cannot be created", e);
throw new ExceptionInInitializerError(e);
}
}

There is also WEB-INF/classes/META-INF/persistence.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>

<persistence>
<persistence-unit name="hska" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>jdbc/hskadb</non-jta-data-source>

<!-- C l a s s e s -->
<class>de.hska.kundenverwaltung.db.KundeEntity</class>
...

<properties>
<!-- P o s t g r e S Q L -->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.connection.url" value="jdbc:postgresql:hskadb"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>

<!-- G e n e r a l -->
<property name="hibernate.connection.isolation" value="2"/>
<property name="hibernate.connection.datasource" value="java:comp/env/jdbc/hskadb"/>
<property name="hibernate.connection.autocommit" value="false"/>
<property name="hibernate.show_sql" value="false"/>

<!-- C a c h i n g -->
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
</properties>
</persistence-unit>
</persistence>

When I start Tomcat the class DbUtil (see above) is initialized and I get this stack trace:
FATAL packaging.PersistenceXmlLoader - hska RESOURCE_LOCAL
FATAL util.DbUtil - Initial EntityManagerFactory cannot be created
javax.persistence.PersistenceException: java.lang.NullPointerException
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:173)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:103)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
at de.hska.util.DbUtil.<clinit>(DbUtil.java:30)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at de.hska.util.HskaFilter.init(HskaFilter.java:29)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:223)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:304)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:77)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3598)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4168)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
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:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.NullPointerException
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:68)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:139)
... 25 more
ERROR [localhost].[/hska] - Exception starting filter dbUtil


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 6:00 am 
Newbie

Joined: Mon Jan 23, 2006 1:11 pm
Posts: 15
Location: Leuven, Belgium
I believe this has been changed in CVS already (i experienced the same nullpointer bug). A workaround is the following:

Code:
Map cfg = new HashMap();
emf = Persistence.createEntityManagerFactory("hska", cfg);

_________________
Don't applaud, throw money (paypal to timvw@users.sourceforge.net) - http://www.timvw.be


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 10:08 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Right, this was a stupid bug from my side. This is fixed in CVS

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.