hi,
I know it's a problem widely discussed, but I read forums from two days and everything looks correct, please help me.
I have netbeans 7, tomcat 7, hibernate 3.6.3 and JavaServer Faces 2.
this is the structure of the project:
Code:
./src:
conf java
./src/conf:
MANIFEST.MF persistence.xml
./src/java:
AppBean.java Bundle.properties Bundles Controller Converter DB Utils
./src/java/Bundles:
Operatore.properties
./src/java/Controller:
OperatoreController.java
./src/java/Converter:
OperatoreConverter.java
./src/java/DB:
Operatore.java
./web:
index.xhtml META-INF operatore.xhtml WEB-INF
./web/META-INF:
context.xml
./web/WEB-INF:
beans.xml faces-config.xml web.xml
and this OperatoreController.java:
Code:
package Controller;
import DB.Operatore;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@ManagedBean(name = "OperatoreController")
@SessionScoped
public class OperatoreController implements Serializable {
@PersistenceContext(unitName = "mPU")
private EntityManager entityManager;
private Operatore x = new Operatore();
public EntityManager getEntityManager() {
return entityManager;
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public Operatore getX() {
return x;
}
public void setX(Operatore x) {
this.x = x;
}
public void aggiungi() {
if (x.getId() == 0) {
x.setId(null);
}
entityManager.persist(x);
}
public void modifica(Object id) {
x = entityManager.find(Operatore.class, id);
}
public void elimina(Object id) {
entityManager.remove(entityManager.find(Operatore.class, id));
}
public List<Operatore> list() {
System.err.println("\n\n" + entityManager + "\n\n");
List<Operatore> list = entityManager.createQuery("FROM Operatore").getResultList();
return list;
}
public Operatore get(Integer id) {
Operatore list = (Operatore) entityManager.createQuery("FROM Operatore AS x WHERE x.id = :id").setParameter("id", id).getSingleResult();
return list;
}
}
from this file I use only "list" function.
this is my persistance.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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/persistence_2_0.xsd">
<persistence-unit name="mPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>DB.Operatore</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/MY_DB"/>
<property name="javax.persistence.jdbc.password" value="MY_PWD"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="MY_USER"/>
</properties>
</persistence-unit>
</persistence>
and finally this is the stack trace:
Code:
java.lang.NullPointerException
at Controller.OperatoreController.list(OperatoreController.java:117)
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 javax.el.BeanELResolver.invoke(BeanELResolver.java:467)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:161)
at org.apache.el.parser.AstValue.getValue(AstValue.java:159)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:193)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:181)
at javax.faces.component.UIData.getValue(UIData.java:557)
at javax.faces.component.UIData.getDataModel(UIData.java:1297)
at javax.faces.component.UIData.setRowIndex(UIData.java:450)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:828)
at javax.faces.component.UIData.encodeBegin(UIData.java:940)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:55)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:46)
at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:225)
at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:148)
at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:75)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:883)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:853)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1652)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Thanks to all