This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ExceptionInInitializerError  RSS feed

 
Rene Ribeiro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good afternoon !!

How do I find out what is this error?
I gather that is the JPAUtil, but could not identify because sometimes can not boot it.

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Cadastro de Contas</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Descricao"/>
<h:inputText value="#{contaBean.conta.descricao}"/>
<h:commandButton value="Salvar" actionListener="#{contaBean.salvar()}"/>
</h:panelGrid>

</h:form>
</h:body>
</html>


package ManagedBean;

import Classes.Conta;
import Util.JPAUtil;
import javax.faces.bean.*;
import javax.persistence.EntityManager;

@ManagedBean(name = "contaBean")
@ViewScoped

public class ContaCorrente {

private Conta conta = new Conta();

public Conta getConta() {
return conta;
}

public void setConta(Conta conta) {
this.conta = conta;
}

public void salvar() {
EntityManager manager = (EntityManager) JPAUtil.getEntityManagerFactory();
manager.getTransaction().begin();
manager.persist(this.conta);
manager.getTransaction().commit();
manager.close();
conta = new Conta();
}

}
package Util;

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

public class JPAUtil{

private static final EntityManagerFactory FACTORY =
Persistence.createEntityManagerFactory("ContaCorrente");

public static EntityManagerFactory getEntityManagerFactory(){
return (EntityManagerFactory) FACTORY.createEntityManager();

}

}

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

<persistence-unit name="ContaCorrente">
<jta-data-source>jdbc/appjsf</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>


<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/conta</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">mysql</property>
</session-factory>
</hibernate-configuration>
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Rene!

There's a "Code" button on our message editor. It inserts tags that make samples of pre-formatted text such as Java code and XML easier to read.

You didn't show the actual error that you are getting, so it's hard to say what's wrong.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!