hibernate gerando java.lang.ExceptionInInitializerError ?

PostgreSQL

Java

Modelagem

24/06/2016

Bom dia galera do fórum!

Seguinte, to me deparando com um problema aqui sempre que tento mapear uma nova classe no hibernate.cgf.xml.

Adicionei uma nova classe em meu projeto dentro do pacote .model e fiz as devidas manipulações e tal. Acontece que preciso dessa nova classe no meu banco, eu estou usando annotation para que o hibernate (versão 4.0.1) faça a criação das tabelas no banco de acordo com minhas @Entity's. Acontece que ao inserir a tag <mapping> no arquivo hibernate.cgf.xml e excecutar o projeto me deparo com o seguinte erro: java.lang.ExceptionInInitializerError.

Pelo que andei observando e testando parece que tem relação com o hibernate pois o stack de erro cita a classe HibernateUtil e se eu tirar a tag <mapping> inserida o projeto roda normalmente. Segue uns códigos abaixo pra lhes deixarem mais a par da situação:

Stack Trace:
javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
	at javax.faces.component.UIViewAction.broadcast(UIViewAction.java:562)
	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
	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:198)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
	at com.delago.matta.controller.ControleDeAcesso.doFilter(ControleDeAcesso.java:56)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
	at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
	at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
	at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
	at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
	at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
	at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ExceptionInInitializerError
	at com.delago.matta.util.HibernateUtil.<clinit>(HibernateUtil.java:29)
	at com.delago.matta.util.Start.startHibernate(Start.java:22)
	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 javax.el.ELUtil.invokeMethod(ELUtil.java:332)
	at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
	at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
	at com.sun.el.parser.AstValue.invoke(AstValue.java:283)
	at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
	at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
	at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
	... 41 more
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.delago.matta.model.Propriedade.tipoPessoa references an unknown entity: com.delago.matta.model.TipoPessoa
	at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:109)
	at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1514)
	at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1437)
	at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
	at com.delago.matta.util.HibernateUtil.<clinit>(HibernateUtil.java:25)
	... 55 more



Hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/DBName</property>
        <property name="hibernate.connection.username">DBUser</property>
        <property name="hibernate.connection.password">DBPassword</property>
    
        <property name="hbm2ddl.auto">update</property>
        
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.format_sql">true</property>
        <property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>
        
        <!-- MAPPING CLASS -->
        <mapping class="caminhoDoPacote.Cidade" /> //tag funciona normal!
        <mapping class="caminhoDoPacote.Estado" /> //tag funciona normal!
        <mapping class="caminhoDoPacote.Usuario" /> //tag funciona normal!
        <mapping class="caminhoDoPacote.Propriedade" /> //tag inserida cujo implica no erro.
    </session-factory>
</hibernate-configuration>



HibernateUtil:
public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) 
            // config file.
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}



Bean para start do hibernate:
@ManagedBean
@SessionScoped
public class Start implements Serializable {

    public void startHibernate() {
        Session session = HibernateUtil.getSessionFactory().openSession();
    }

}


Classe Propriedade.java (a qual não consigo mapear):
@Entity
@Table(name = "propriedade")
public class Propriedade implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "nome", nullable = false)
    private String nome;

    @Column(name = "email", nullable = true, columnDefinition = "")
    private String email;

    @Column(name = "end_logadouro", nullable = false)
    private String endLogadouro;

    @Column(name = "end_logadouronumero", nullable = true, columnDefinition = "")
    private String endLogadouroNumero;

    @Column(name = "bairro", nullable = false)
    private String bairro;

    @Column(name = "cep", nullable = true, columnDefinition = "")
    private String cep;

    @Column(name = "telefone", nullable = false)
    private String telefone;

    @Column(name = "celular", nullable = true, columnDefinition = "")
    private String celular;

    @Column(name = "cpf_cnpj", nullable = false)
    private String cpfCnpj;

    @Column(name = "insc_estadual", nullable = false)
    private String incsEstadual;

    @Column(name = "total_hectares", nullable = false)
    private Double totalHectares;

    @ManyToOne
    @JoinColumn(name = "id_cidade", nullable = false)
    private Cidade cidade;

    @ManyToOne
    @JoinColumn(name = "tipo_pessoa", nullable = true)
    private TipoPessoa tipoPessoa;

    /**
     * DADOS DE COBRANCA DE PROPIEDADE
     */
    @ManyToOne
    @JoinColumn(name = "id_cidadecobranca", nullable = true)
    private Cidade cidadeCobranca;

    @Column(name = "end_cobranca", nullable = true, columnDefinition = "")
    private String endCobranca;

    @Column(name = "end_cobrancanumero", nullable = true, columnDefinition = "")
    private String endCobrancaNumero;

    @Column(name = "end_cobrancabairro", nullable = true, columnDefinition = "")
    private String endCobrancaBairro;

    @Column(name = "cep_cobranca", nullable = true, columnDefinition = "")
    private String cep_cobranca;
    
    //Getters & Setters




Classe usuario.java(só pra coparação, está está mapeada certo e até excluí ela do banco pra ver se estava sendo criada e está!):
@Entity
@Table(name = "usuario")
public class Usuario implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", nullable = false, unique = true)
    private Long id;

    @Column(name = "userName", nullable = false, unique = true)
    private String nomeUsuario;

    @Column(name = "password", nullable = false, unique = false)
    private String senha;

    @Column(name = "lastAccess")
    @Type(type = "caminhoPacote.LocalDateTimeUserType")
    private LocalDateTime ultimoAcesso;

    //Getters & Setters



Se alguém souber identificar o porque algumas dessas classes me gera o erro java.lang.ExceptionInInitializerError, ficaria agradecido!


Valeu :D
Rafael

Rafael

Curtidas 0

Respostas

Rafael

Rafael

24/06/2016

Resolvido! Era erro de noob msmo! Desconsiderar este post! Serei mais atendo nos próximos
GOSTEI 0
POSTAR