I'm trying to create my first project using JPA, I use Jboss 5, Oracle, Hibernate and primefaces. After doing the project deploy I try to create and inseir a new client in the bank through the web interface, but I am getting the following error:
exception
javax.servlet.ServletException: java.lang.ExceptionInInitializerError
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause
javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause
java.lang.ExceptionInInitializerError
Beans.ClienteBean.insertPedido(ClienteBean.java:27)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:170)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause
javax.persistence.PersistenceException: [PersistenceUnit: MC] Unable to build EntityManagerFactory
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
com.bd.JpaUtil.<clinit>(JpaUtil.java:10)
Beans.ClienteBean.insertPedido(ClienteBean.java:27)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:170)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause
org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
org.hibernate.cache.impl.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:79)
org.hibernate.cache.UpdateTimestampsCache.<init>(UpdateTimestampsCache.java:58)
org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:369)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
com.bd.JpaUtil.<clinit>(JpaUtil.java:10)
Beans.ClienteBean.insertPedido(ClienteBean.java:27)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:170)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lif'enter code here'ecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96
My persistence.xml:
<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="MC" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/gt</jta-data-source>
<non-jta-data-source>jdbc/gt</non-jta-data-source>
<properties>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle8iDialect" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.cache.use_second_level_cache"
value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
ClientBean:
package Beans;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import com.bd.Cliente;
import com.bd.JpaUtil;
import Repository.ClienteRepository;
@ManagedBean(name = "ClienteBean")
public class ClienteBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Cliente cliente = new Cliente();
private static List<Cliente> listaClientes;
public void insertPedido() {
System.out.println(cliente);
EntityManager manager = JpaUtil.getEntityManager();
ClienteRepository.insertCliente(cliente, manager);
}
public void updatePedido() {
ClienteRepository.updateCliente(cliente);
}
public void delete() {
ClienteRepository.delete(cliente);
}
public void todosNomes() {
listaClientes = ClienteRepository.todosNomes();
}
public void todosClientes() {
listaClientes = ClienteRepository.todos();
}
public void consutaPorId(int id) {
cliente = ClienteRepository.consultaCliente(id);
}
public static void consultaPorCpf(Cliente cliente) {
listaClientes = ClienteRepository.consultaPorCpf(cliente);
}
public static void consultaPorNome(Cliente cliente) {
listaClientes = ClienteRepository.consultaPorNome(cliente);
}
public Cliente getCliente() {
return cliente;
}
public List<Cliente> getListaClientes() {
return listaClientes;
}
}
ClientRepository:
package Repository;
import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.transaction.TransactionScoped;
import javax.transaction.Transactional;
import javax.transaction.Transactional.TxType;
import com.bd.Cliente;
public class ClienteRepository implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private static EntityManager manager;
static EntityTransaction trx;
public static void setManager(EntityManager manager) {
ClienteRepository.manager = manager;
trx = manager.getTransaction();
}
public static void insertCliente(Cliente cliente) {
trx.begin();
manager.persist(cliente);
trx.commit();
}
public static void updateCliente(Cliente cliente) {
Cliente resultado = new Cliente();
trx.begin();
if (cliente == null)
return;
resultado = consultaCliente(cliente.getId());
if (!cliente.getCpf().equals(""))
resultado.setCpf(cliente.getCpf());
if (!cliente.getNome().equals(""))
resultado.setNome(cliente.getNome());
if (!cliente.getRg().equals(""))
resultado.setRg(cliente.getNome());
manager.merge(resultado);
trx.commit();
}
public static void delete(Cliente cliente) {
cliente = consultaCliente(cliente.getId());
trx.begin();
manager.remove(cliente);
trx.commit();
}
public static Cliente consultaCliente(int id) {
Cliente resultado = manager.find(Cliente.class, id);
return resultado;
}
public static List<Cliente> consultaPorCpf(Cliente cliente) {
Query query = manager.createNamedQuery("Cliente.buscaPorCpf");
query.setParameter("cpf", cliente.getCpf());
return query.getResultList();
}
public static List<Cliente> todosNomes() {
Query query = manager.createNamedQuery("Cliente.todosNomes");
return query.getResultList();
}
public static List<Cliente> todos() {
Query query = manager.createNamedQuery("Cliente.todos");
return query.getResultList();
}
public static List<Cliente> consultaPorNome(Cliente cliente) {
Query query = manager.createNamedQuery("Cliente.buscaPorNome");
query.setParameter("nome", cliente.getNome());
return query.getResultList();
}
}
JpaUtil:
package com.bd;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class JpaUtil {
private static EntityManagerFactory factory;
static {
factory = Persistence.createEntityManagerFactory("MC");
}
public static EntityManager getEntityManager() {
return factory.createEntityManager();
}
}
Thanks in advance for any help!