TOMCAT JSF JPA com Hibernate

02/10/2009

4

Opa,, eu tenho uma pequena app que usa JSF JPA e Hibernate.. Quando eu rodo essa app como standalone td funciona... mas quando eu rodo no Tomcat dá erro..

se alguém puder ajudar eu agradeço..


arquivo de persistência:
 <?xml version="1.0" encoding="UTF-8"&63>  
 <persistence version="1.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_1_0.xsd">  
     <persistence-unit name="pu1">  
         <properties>  
             <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>  
             <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jpafullexample"/>  
             <property name="hibernate.connection.user" value="root"/>  
             <property name="hibernate.connection.password" value="pws"/>  
             <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>  
             <property name="hibernate.show_sql" value="true"/>  
         </properties>  
     </persistence-unit>  
 </persistence>


Essa classe retorna o entity manager
[code:1:1e29369caf]
 public class JpaUtil {    
   
      private static JpaUtil me;    
     private EntityManagerFactory factory;    
           
      private JpaUtil () {    
          factory = Persistence.createEntityManagerFactory("pu1");    
      }    
         
     public static JpaUtil getInstance() {    
          if (me == null) {    
              me = new JpaUtil();    
          }    
          return me;    
      }    
          
     public EntityManager createEntityManager() {    
         EntityManager em = factory.createEntityManager();    
          em.getTransaction().begin();    
          return em;    
      }    
  }    


Esse é meu managedBean
 public class FirstJsfandjpa {    
      
     private List<People> people;    
          
     public FirstJsfandjpa() {    
          EntityManager em = (EntityManager) JpaUtil.getInstance().createEntityManager();    
         people = em.createQuery("select pl from People pl").getResultList();    
          em.getTransaction().commit();    
          em.close();    
      }    
      
      public List<People> getPeople() {    
          return people;    
      }    
      
      public void setPeople(List<People> people) {    
          this.people = people;    

  }    


quando eu executo dessa classe td funciona
 public class Execute {    
    
      List<People> people = new FirstJsfandjpa().getPeople();    
         
     public static void main(String[] args) {    
             
         List<People> people = new FirstJsfandjpa().getPeople();    
             
          for (People pl: people) {    
             System.out.println(pl.getName());    
          }    
      }    
  }    


Mas quando eu executo de uma página JSF no tomcat dá erro:
  <¬@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"¬>    
  <¬@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"¬>    
  <¬@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"¬>    
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">    
  <html>    
  <head>    
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">    
  <title>JSF and JPA example</title>    
  </head>    
  <body>    
  <f:view>    
       <h1><h:outputText value="People listed" /></h1>    
      <h:dataTable var="people" value="{FirstJsfandjpa.people}">    

             <f:facet name="header">    
                  <h:outputText value="Name" />    
              </f:facet>    
              <h:outputText value="#{people.name}" />    
         </h:column>    
      </h:dataTable>    
  </f:view>    
 </body>    
  </html>    


HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.NoClassDefFoundError: javax/persistence/Persistence
br.com.devmedia.entity.JpaUtil.<init>(JpaUtil.java:13)
br.com.devmedia.entity.JpaUtil.getInstance(JpaUtil.java:1
br.com.devmedia.faces.FirstJsfandjpa.<init>(FirstJsfandjpa.java:16)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
java.lang.Class.newInstance0(Class.java:355)
java.lang.Class.newInstance(Class.java:30
com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:185)
com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)

com.sun.faces.mgbean.BeanManager.create(BeanManager.java:222)
com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
org.apache.el.parser.AstValue.getValue(AstValue.java:107)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101)
javax.faces.component.UIData.getValue(UIData.java:614)
javax.faces.component.UIData.getDataModel(UIData.java:1129)
javax.faces.component.UIData.setRowIndex(UIData.java:451)
com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:77)
javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
javax.faces.component.UIData.encodeBegin(UIData.java:967)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:92
javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:266)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:197)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
Responder

Posts

02/10/2009

Dyego.carmo

Opa !

Falta as bibliotecas do JPA

Tente colocar no LIB do TOMCAT:

hibernate-entitymanager.jar

E teste.
Responder

02/10/2009

Dyego.carmo

E tambem o ejb3-persistence.jar
Responder

05/10/2009

Anonymous

valeu Diego.. era isso mesmo..
Responder

05/10/2009

Dyego.carmo

Opa !

Que bom :D

Valeuz !
Responder

08/06/2010

Carlos Mazzi

REsolveu? entao pode fechar o chamado, amigo. Abracos++
Responder

11/06/2010

Dyego Carmo

Resolvido ?
Responder
×
+1 DevUP
Acesso diário, +1 DevUP
Parabéns, você está investindo na sua carreira