8
respostas

java.lang.NoClassDefFoundError

Boa noite,

Estou tentando fazer um projeto usando JSF e Hibernate, mas estou recebendo a exception abaixo quando ustilizo o comando: EntityManager em = JPAUtil.getEntityManager();

nov 12, 2016 10:41:50 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
ADVERTÊNCIA: #{automovelBean.grava}: java.lang.NoClassDefFoundError: javax/persistence/Persistence
javax.faces.FacesException: #{automovelBean.grava}: java.lang.NoClassDefFoundError: javax/persistence/Persistence
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:117)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:791)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1256)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.faces.el.EvaluationException: java.lang.NoClassDefFoundError: javax/persistence/Persistence
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:101)
    ... 28 more
Caused by: java.lang.NoClassDefFoundError: javax/persistence/Persistence
    at dao.JPAUtil.<clinit>(JPAUtil.java:9)
    at managedBean.AutomovelBean.grava(AutomovelBean.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    ... 29 more
Caused by: java.lang.ClassNotFoundException: javax.persistence.Persistence
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
    ... 39 more

nov 12, 2016 10:41:50 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/lojaDeAutomoveis] threw exception [java.lang.NoClassDefFoundError: javax/persistence/Persistence] with root cause
java.lang.ClassNotFoundException: javax.persistence.Persistence
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
    at dao.JPAUtil.<clinit>(JPAUtil.java:9)
    at managedBean.AutomovelBean.grava(AutomovelBean.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:101)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:791)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1256)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

Parece um problema de biblioteca, mas acredito ter colocado todos jars necessários:

antlr-2.7.7, 
dom4j-1.6.1,  
hibernate-commons-annotations-4.0.1.Final,
hibernate-core-4.2.0.Final,
hibernate-entitymanager-4.2.0.Final,
hibernate-jpa-2.0-api-1.0.1.Final, 
javassist-3.15.0-GA,
jboss-logging-3.1.0.GA,
jboss-transaction-api_1.1_spec-1.0.0.Final,
mysql-connector-java-5.1.24-bin,
javax.faces-2.1.14

Meu persistence.xml:

<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/persistence_2_0.xsd"
                version            = "2.0">

    <persistence-unit name="unidadeDePersistencia">                        <!-- banco usado -->
        <provider>org.hibernate.ejb.HibernatePersistence</provider>     <!-- indica a implementacao usada: hibernate, EclipseLink, OpenJPA, Batoo etc -->
        <class>modelo.Automovel</class>                                    <!-- entidades -->

        <properties>                                                    
            <property name="javax.persistence.jdbc.driver"      value="com.mysql.jdbc.Driver" />                        <!-- driver JDBC utilizado (jar deve estar na aplicacao) -->
            <property name="javax.persistence.jdbc.url"      value="jdbc:mysql://localhost/unidadeDePersistencia" />
            <property name="javax.persistence.jdbc.user"      value="root" />
            <property name="javax.persistence.jdbc.password" value="1234" />

            <property name="hibernate.dialect"         value="org.hibernate.dialect.MySQL5InnoDBDialect" />    <!-- indicamos qual a classe do Hibernate que possui a implementacao do dialeto -->
            <property name="hibernate.hbm2ddl.auto" value="update" />                                        <!-- gera tabelas e colunas com os nomes criados pra entidades e atributos -->
            <property name="hibernate.show_sql"     value="true" />
            <property name="hibernate.format_sql"     value="true" />
        </properties>
    </persistence-unit>

</persistence>

Meu bean:

package managedBean;

import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import dao.JPAUtil;
import modelo.Automovel;

@ManagedBean                //integra a view com a regra de negocio
public class AutomovelBean {

    private Automovel automovel = new Automovel();

    public Automovel getAutomovel() {
        return this.automovel;
    }

    public void setAutomovel(Automovel automovel) {
        this.automovel = automovel;
    }

    public void grava(){
        System.out.println("Gravando objeto modelo: " + this.getAutomovel().getModelo());

        EntityManager em = JPAUtil.getEntityManager();

        /*EntityTransaction tx = em.getTransaction();
        tx.begin();
        em.persist(this.automovel);
        tx.commit();
        em.close();*/
    }
}

Grato pela ajuda!

8 respostas

Olá Tiago

É isso mesmo, está faltando o JAR da especificação da JPA, que é esse: https://mvnrepository.com/artifact/org.eclipse.persistence/javax.persistence/2.0.0

Se você está usando o maven ou similar vai ser fácil. Caso contrário vai ter de por esse JAR e talvez alguns outros que ele vai reclamar depois.

Olá Paulo,

Aparentemente deu o mesmo erro:

'''

Gravando objeto modelo: asfd nov 13, 2016 4:07:14 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute ADVERTÊNCIA: #{automovelBean.grava}: java.lang.NoClassDefFoundError: javax/persistence/Persistence javax.faces.FacesException: #{automovelBean.grava}: java.lang.NoClassDefFoundError: javax/persistence/Persistence at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:117) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:791) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1256) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: javax.faces.el.EvaluationException: java.lang.NoClassDefFoundError: javax/persistence/Persistence at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:101) ... 28 more Caused by: java.lang.NoClassDefFoundError: javax/persistence/Persistence at dao.JPAUtil.(JPAUtil.java:9) at managedBean.AutomovelBean.grava(AutomovelBean.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.el.parser.AstValue.invoke(AstValue.java:247) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) ... 29 more Caused by: java.lang.ClassNotFoundException: javax.persistence.Persistence at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167) ... 39 more

nov 13, 2016 4:07:14 PM org.apache.catalina.core.StandardWrapperValve invoke GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/lojaDeAutomoveis] threw exception [java.lang.NoClassDefFoundError: javax/persistence/Persistence] with root cause java.lang.ClassNotFoundException: javax.persistence.Persistence at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167) at dao.JPAUtil.(JPAUtil.java:9) at managedBean.AutomovelBean.grava(AutomovelBean.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.el.parser.AstValue.invoke(AstValue.java:247) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:101) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:791) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1256) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

'''

Tirei um print da tela https://s22.postimg.org/e4x2hx5bl/Captura_de_tela.png. Nele mostra que adicionei o jar que tu passou ao build path.

Tem alguma sugestão?

Grato!

Realmente ela está no build path. Unica possibilidade de ele nao estar achando é se o seu build path nao é o mesmo path de execucao do servidor. Por onde voce está executando seu application server? Ant? Maven? pode por o codigo?

Estou executando o application server simplesmente dando um "Start" no TomCat. É obrigatório usar o Ant ou Mavem para um projeto usando JSF e Hibernate?

Abaixo meu código: '''

package managedBean;

import javax.faces.bean.ManagedBean; import javax.persistence.EntityManager; import javax.persistence.EntityTransaction;

import dao.JPAUtil; import modelo.Automovel;

@ManagedBean //integra a view com a regra de negocio public class AutomovelBean {

private Automovel automovel = new Automovel();

public Automovel getAutomovel() { return this.automovel; }

public void setAutomovel(Automovel automovel) { this.automovel = automovel; }

public void grava(){ System.out.println("Gravando objeto modelo: " + this.getAutomovel().getModelo());

EntityManager em = JPAUtil.getEntityManager();

/EntityTransaction tx = em.getTransaction(); tx.begin(); em.persist(this.automovel); tx.commit(); em.close();/ } }

package modelo;

import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id;

@Entity public class Automovel {

@Id @GeneratedValue(strategy=GenerationType.IDENTITY) //IDENTITY usa MySQL private Long id; private String marca; private String modelo; private Integer anoModelo; private Integer anoFabricacao; private String observacoes;

public Long getId() { return id; }

public void setId(Long id) { this.id = id; }

public String getMarca() { return this.marca; }

public void setMarca(String marca) { this.marca = marca; }

public String getModelo() { return this.modelo; }

public void setModelo(String modelo) { this.modelo = modelo; }

public Integer getAnoModelo() { return anoModelo; }

public void setAnoModelo(Integer anoModelo) { this.anoModelo = anoModelo; }

public Integer getAnoFabricacao() { return this.anoFabricacao; }

public void setAnoFabricacao(Integer anoFabricacao) { this.anoFabricacao = anoFabricacao; }

public String getObservacoes() { return this.observacoes; }

public void setObservacoes(String observacoes) { this.observacoes = observacoes; } }

package dao;

import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence;

public class JPAUtil {

private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("unidadeDePersistencia");

public static EntityManager getEntityManager(){ return emf.createEntityManager(); }}

''' '''

<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/persistence_2_0.xsd" version = "2.0">

org.hibernate.ejb.HibernatePersistence

modelo.Automovel

'''

Gratidão pela força!

Opa, não é obrigatório, mas como foi que vc adicionou a dependência? Você colocou ela diretamente na pasta WEB-INF/lib?

Adicionei uma pasta "lib" no projeto. Nessa pasta coloquei todos . jar e depois adicionei ao build path.

Essa pasta lib, está dentro da pasta WEB-INF? Isso eh obrigatório.

entra no diretorio via filesystem e manda um printscreen pra gente? dele deploiado