0 Replies Latest reply on Feb 26, 2009 3:13 PM by Alex Dorandish

    JBoss Hibernate Doesn't work

    Alex Dorandish Newbie

      development environment:
      I am using NetBeans IDE to code. And I created my hibernate classes using the wizard from netBeans.

      my server:
      jbossesb-server-4.4.GA

      Here is my hibernate.cfg:

      <?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.MySQLDialect</property>
       <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
       <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/cayenta</property>
       <property name="hibernate.connection.username">cayenta</property>
       <property name="hibernate.connection.password">password</property>
       <mapping class="com.cayenta.service.hibernate.SubmenuApplication"/>
       <mapping class="com.cayenta.service.hibernate.Menu"/>
       <mapping class="com.cayenta.service.hibernate.CayentaHibernateUtil"/>
       </session-factory>
      </hibernate-configuration>
      


      here is my entity:

      package com.cayenta.service.hibernate;
      // Generated Feb 26, 2009 9:47:06 AM by Hibernate Tools 3.2.1.GA
      
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import static javax.persistence.GenerationType.IDENTITY;
      import javax.persistence.Id;
      import javax.persistence.Table;
      
      /**
       * Menu generated by hbm2java
       */
      @Entity
      @Table(name="menu"
       ,catalog="cayenta"
      )
      public class Menu implements java.io.Serializable {
      
      
       private Integer id;
       private String name;
       private Integer menuId;
      
       public Menu() {
       }
      
       public Menu(String name, Integer menuId) {
       this.name = name;
       this.menuId = menuId;
       }
      
       @Id @GeneratedValue(strategy=IDENTITY)
      
       @Column(name="id", unique=true, nullable=false)
       public Integer getId() {
       return this.id;
       }
      
       public void setId(Integer id) {
       this.id = id;
       }
      
       @Column(name="name", length=16777215)
       public String getName() {
       return this.name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       @Column(name="menu_id")
       public Integer getMenuId() {
       return this.menuId;
       }
      
       public void setMenuId(Integer menuId) {
       this.menuId = menuId;
       }
      
      
      
      
      }
      


      here is my util class:
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      
      package com.cayenta.service.hibernate;
      
      
      import org.hibernate.cfg.AnnotationConfiguration;
      import org.hibernate.SessionFactory;
      
      /**
       * Hibernate Utility class with a convenient method to get Session Factory object.
       *
       * @author dorand
       */
      public class CayentaHibernateUtil {
       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;
       }
      }
      
      


      when I deploy it and run it I get the following exception:
      java.lang.ClassCastException: org.hibernate.validator.event.ValidateEventListener
       at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:819)
       at com.cayenta.service.hibernate.CayentaHibernateUtil.<clinit>(CayentaHibernateUtil.java:24)
       at com.cayenta.web.Test.processRequest(Test.java:38)
       at com.cayenta.web.Test.doGet(Test.java:69)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
       at java.lang.Thread.run(Thread.java:613)
      
      


      I assumed that somehow the libraries are not matched. so I removed my hibernate libraries from my webapp/lib folder and redeployed it again so this time I use the one that is in the jboss/server/default/lib

      here is my web lib folder before removing the libs:
      streambuffer.jar
      activation.jar
      antlr-2.7.6.jar
      asm-attrs.jar
      asm.jar
      cglib-2.1.3.jar
      commons-collections-2.1.1.jar
      commons-logging-1.1.jar
      dom4j-1.6.1.jar
      ehcache-1.2.3.jar
      FastInfoset.jar
      hibernate-annotations.jar
      hibernate-commons-annotations.jar
      hibernate-entitymanager.jar
      hibernate-tools.jar
      hibernate3.jar
      http.jar
      javassist.jar
      jaxb-api.jar
      jaxb-impl.jar
      jaxb-xjc.jar
      jaxws-api.jar
      jaxws-rt.jar
      jaxws-tools.jar
      jdbc2_0-stdext.jar
      jsr173_api.jar
      jsr181-api.jar
      jsr250-api.jar
      jta.jar
      mimepull.jar
      mysql-connector-java-5.1.6-bin.jar
      resolver.jar
      saaj-api.jar
      saaj-impl.jar
      sjsxp.jar
      stax-ex.jar

      here is the list after I removed the libs:
      activation.jar
      FastInfoset.jar
      http.jar
      jaxb-api.jar
      jaxb-impl.jar
      jaxb-xjc.jar
      jaxws-api.jar
      jaxws-rt.jar
      jaxws-tools.jar
      jsr173_api.jar
      jsr181-api.jar
      jsr250-api.jar
      mimepull.jar
      mysql-connector-java-5.1.6-bin.jar
      resolver.jar
      saaj-api.jar
      saaj-impl.jar
      sjsxp.jar
      stax-ex.jar
      streambuffer.jar

      here is the error message I get after removing the duplicated libs:
      java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
       at java.lang.Class.getConstructor0(Class.java:2678)
       at java.lang.Class.getDeclaredConstructor(Class.java:1953)
       at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:357)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
       at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
       at com.cayenta.service.hibernate.CayentaHibernateUtil.<clinit>(CayentaHibernateUtil.java:24)
       at com.cayenta.web.Test.processRequest(Test.java:38)
       at com.cayenta.web.Test.doGet(Test.java:69)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
       at java.lang.Thread.run(Thread.java:613)
      
      


      what is going on?