-->
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: Null Pointer on Entity Manager
PostPosted: Thu Mar 31, 2011 10:43 am 
Newbie

Joined: Thu Mar 31, 2011 10:16 am
Posts: 3
I am fairly new to all of this hibernate, and annotations etc...
the entity manager is not getting injected. It is always null. Any help would be great, as well as why it is wrong. Thanks


I am using the following:
java jdk 1.6.0_23
eclipse helios
Hibernate 3
jsf 2.0 and icefaces
tomcat v6 server
derby database

Here is the code:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Lohf</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<description>Google Maps API key is required if gMap component is used. Sign up for an API key from http://code.google.com/apis/maps/signup.html</description>
<param-name>com.icesoft.faces.gmapKey</param-name>
<param-value>ABQIAAAADlu0ZiSTam64EKaCQr9eTRTOTuQNzJNXRlYRLknj4cQ89tFfpxTEqxQnVWL4k55OPICgF5_SOZE06A</param-value>
</context-param>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
</web-app>


persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_2_0.xsd"
version="2.0">

<persistence-unit name="lohf">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<properties>
<!-- <property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml"/>
<property name="hibernate.hbm2ddl.auto" value="create"/> -->
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="hibernate.connection.url" value="jdbc:derby:/test;create=true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.timeout" value="300" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
</properties>
</persistence-unit>
</persistence>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-f ... ig_2_0.xsd"
version="2.0">



<managed-bean>
<managed-bean-name>navigationDAO</managed-bean-name>
<managed-bean-class>com.dao.NavigationDAO</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

<managed-bean>
<managed-bean-name>navigationBean</managed-bean-name>
<managed-bean-class>com.beans.NavigationBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>navigationDAO</property-name>
<property-class>com.dao.NavigationDAO</property-class>
<value>#{navigationDAO}</value>
</managed-property>
</managed-bean>
</faces-config>

DAO


package com.dao;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.entity.LohfMenuItem;

public class NavigationDAO {

private EntityManager entityManager;

@SuppressWarnings("unchecked")
public List<LohfMenuItem> getMenuItems()
{
List<LohfMenuItem> menuItems = new ArrayList<LohfMenuItem>();
***getting null pointer here --> menuItems = (List<LohfMenuItem>)entityManager.createQuery("from LOHF.MENUITEMS").getResultList();
return menuItems;
}

@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
}

Method in the Bean that is called

@Transactional
public List<LohfMenuItem> getMenuItems() {

menuItems = navigationDAO.getMenuItems();
return menuItems;
}

* note i have tried with and without the @Transactional tag

here is the list of jar files in my web/lib folder, i have a lot because through trying to find solutions i keep adding jars that i see others have. On a side note if anyone knows which jars i don't need I can remove them.

ant-contrib-1.0b2.jar
ant-junit-1.6.5.jar
antlr.jar
antlr-2.7.6.jar
asm.jar
asm-attrs.jar
c3p0-0.9.1.jar
cglib-2.2.jar
commons-beanutils.jar
commons-collections.jar
commons-collections-3.1.jar
commons-digester.jar
commons-logging.jar
dom4j.jar
dom4j-1.6.1.jar
ehcache-1.5.0.jar
ejb3-persistence.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-core.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate-testing.jar
icefaces.jar
infinispan-core-4.2.1.CR1.jar
ivy-1.4.1.jar
javassist.jar
javassist-3.12.0.GA.jar
jbosscache-core-3.2.1.GA.jar
jsf-api.jar
jsf-impl.jar
jstl.jar
jta.jar
jta-1.1.jar
junit.jar
junit-3.8.1.jar
krysalis-jCharts-1.0.0-alpha-1.jar
log4j.jar
maven-ant-tasks.jar
org.springframework.core-3.1.0.M1.jar
org.springframework.core-sources-3.1.0.M1.jar
org.springframework.jdbc-3.1.0.M1.jar
org.springframework.jdbc-sources-3.1.0.M1.jar
org.springframework.transaction-3.1.0.M1.jar
oscache-2.1.jar
proxool-0.8.3.jar
slf4j-api.jar
slf4j-api-1.6.1.jar
slf4j-log4j12.jar
swarmcache-1.0RC2.jar


Top
 Profile  
 
 Post subject: Re: Null Pointer on Entity Manager
PostPosted: Fri Apr 01, 2011 2:39 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
This is a question for the Hibernate Use Forum. I recommend you redefine your question though. Have you check the log. Is there hibernate output? Does Hibernate bootstrap? Is there an exception?

--Hardy


Top
 Profile  
 
 Post subject: Re: Null Pointer on Entity Manager
PostPosted: Fri Apr 01, 2011 12:14 pm 
Newbie

Joined: Thu Mar 31, 2011 10:16 am
Posts: 3
Ok, I added my post under Hibernate Users.


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.