0

Problem with Hibernate, How to configure to work with Zkoss?

asked 2013-01-21 22:55:36 +0800

rumenigg gravatar image rumenigg
12

updated 2013-01-22 05:13:43 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Hello, I'm trying to configure my application to run with Hibernate but it doesen't work, there is a problem that I can't identify. The problem is:

Jan 21, 2013 4:49:27 PM org.hibernate.cfg.Configuration configure INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml Jan 21, 2013 4:49:27 PM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: HHH000040: Configuration resource: /hibernate.cfg.xml Jan 21, 2013 4:49:27 PM org.hibernate.cfg.Configuration doConfigure INFO: HHH000041: Configured SessionFactory: null Jan 21, 2013 4:49:27 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1352 SEVERE:

java.lang.NoSuchMethodError: org.hibernate.cfg.AnnotationConfiguration.getEventListeners()Lorg/hibernate/event/EventListeners; at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:771) at br.com.rti.alpha.controle.Logar.confirm(Logar.java:55) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.zkoss.zk.ui.select.Selectors$ComposerEventListener.onEvent(Selectors.java:681) at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2742) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2713) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2654) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136) at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1710) at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1495) at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1205) at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:583) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:481) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:489) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619)

And always a click in the button has this problem.

Follow my code: Hibernate.cfg.xml

Source Code
<?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.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/hydro_alpha</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.format_sql">true</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <mapping class="br.com.rti.alpha.modelo.pessoa.Pessoa"/>
        <mapping class="br.com.rti.alpha.modelo.pessoa.Funcao"/>
    </session-factory>
</hibernate-configuration>

zk.xml

Source Code
<zk>
    <device-config>
        <device-type>ajax</device-type>
        <timeout-uri>/timeout.zul</timeout-uri><!-- An empty URL can cause the browser to reload the same URL -->
    </device-config>


</zk>

HibernateUtil.java

Source Code
package br.com.rti.alpha.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

public class HibernateUtil 
{
    private static final SessionFactory sessionFactory;

    static
    {
        try
        {       
            Configuration conf = new AnnotationConfiguration();
            conf.configure();
            sessionFactory = conf.buildSessionFactory();
        }
        catch (Throwable ex) 
        {

            System.err.println("A criação da SessionFactory falhou." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }

    public static Session openSession()
    {
        return sessionFactory.getCurrentSession();
    }
}

DaoFactory.java

Source Code
package br.com.rti.alpha.dao;



import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.rti.alpha.modelo.pessoa.Pessoa;
import br.com.rti.alpha.util.HibernateUtil;


public class DaoFactory 
{
    private Session session;
    private Transaction transaction;

    public DaoFactory()
    {
        this.session = HibernateUtil.openSession();
    }

    public DaoFactory(Session session)
    {
        this.session = session;
    }

    public void beginTransaction()
    {
        this.transaction = this.session.beginTransaction();
    }

    public void commit()
    {
        this.transaction.commit();
        this.transaction = null;
    }

    public boolean hasTransaction()
    {
        return this.transaction != null;
    }

    public void rollback()
    {
        this.transaction.rollback();
        this.transaction = null;
    }

    public void close()
    {
        this.session.close();       
    }

    public Dao<Pessoa> getPessoaDao()
    {
        return new Dao<Pessoa>(this.session, Pessoa.class);
    }

    public PessoaDAO getPessoaDAO()
    {
        return new PessoaDAO(this.session);
    }
}

The listener where I wired the components Logar.java

Source Code
package br.com.rti.alpha.controle;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Label;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

import br.com.rti.alpha.dao.DaoFactory;
import br.com.rti.alpha.dao.PessoaDAO;
import br.com.rti.alpha.modelo.pessoa.Pessoa;
import br.com.rti.alpha.util.HibernateUtil;

public class Logar extends SelectorComposer<Window>
{
    /**br.Login
     * 
     */

    @Wire
    private Textbox matricula;
    @Wire
    private Textbox senha;
    @Wire
    private Label msg;
    @Wire
    private Hbox hboxlogin;
    @Wire("princ")
    private Component princ;



    @Listen("onClick=#btnLogin")
    public void confirm()
    {

        Pessoa pessoa = new Pessoa();
        pessoa.setMatricula(matricula.getValue());
        pessoa.setSenha(senha.getValue());
        alert("Teste de ligação de componente\nMatrícula: " + pessoa.getMatricula() +"\nSenha: " + pessoa.getSenha());

        try
        {           
            DaoFactory daof = new DaoFactory();
            //daof.beginTransaction();
            /*PessoaDAO pdao = daof.getPessoaDAO();

            pessoa = pdao.existePessoa(pessoa);

            if ( pessoa != null )
            {
                this.hboxlogin.setVisible(false);
            }
            else
            {
                Clients.evalJavaScript("loginFaild()");
            }*/

        }
        catch (Exception e)
        {
            //e.printStackTrace();
            alert("Problema de conexão com o Banco de Dados");

            e.printStackTrace();
        }       
    }
}

I tested with a simple class, and insert manual datas and the hibernate ran, worked, inserted datas in my database, MySQL. So, I think this problem is with the zkoss. Thank you for the attention. And I really tried everything.

delete flag offensive retag edit

3 Answers

Sort by » oldest newest most voted
0

answered 2013-01-22 05:36:14 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

You can check with my blog here

link publish delete flag offensive edit

Comments

Wich version of Hibernate Did you use in habernate mapping examples? Because I'm trying to do my HibernateUtil class and in this line, factory=config.buildSessionFactory(serviceRegistry), on method getSession(), and it doesn't accept the argument serviceRegistry. I really understood. Thank you

rumenigg ( 2013-01-23 19:01:22 +0800 )edit
0

answered 2013-01-22 06:16:27 +0800

hawk gravatar image hawk
2837 1 5
http://hawkphoenix.blogsp... ZK Team

Hi, Which version of Hibernate do you use? AnnotationConfiguration is deprecated at Hibernate 4.0. You should use new Configuration().configure().

link publish delete flag offensive edit
0

answered 2013-01-22 11:35:39 +0800

rumenigg gravatar image rumenigg
12

Hi Hawk, I´m using Hibernate4 but I tried to use Configuration().configure() and nothing either. I´ll try other time to use Configuration().configure() and I´ll post here the results.

And Senthilchettyin, I´m going to see your blog toonight and pos here my results too.

Thank you boys.

link publish delete flag offensive edit

Comments

Please dont post question as a answer if you will want to say something to anyone please use post a comment link please follow forum standard

sjoshi ( 2013-01-22 12:01:59 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2013-01-21 22:55:36 +0800

Seen: 68 times

Last updated: Jan 22 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More