0

help with zk+hibernate+sring

asked 2012-03-08 19:12:21 +0800

amina2011 gravatar image amina2011
33 1

Hi,
I'm not sure this is the wright forum, but i will try ^^
I've tried to follow this http://books.zkoss.org/wiki/Small_Talks/2011/December/Integrate_ZK5_with_Spring_3_and_Hibernate#By_ZK_Studio
but when i try to run the person.zul page I get this


java.lang.VerifyError: class com.mysql.jdbc.ByteArrayBuffer overrides final method readLength.()J
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2820)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1150)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2006)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1969)
at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1858)
at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1826)
at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1812)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1306)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:896)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:322)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5103)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.startup.Catalina.start(Catalina.java:621)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)

I think i'm missing some jars, does anyone have suggsetions ???
regards

delete flag offensive retag edit

9 Replies

Sort by » oldest newest

answered 2012-03-08 19:23:49 +0800

blacksensei gravatar image blacksensei
234 2

Hello there can you post your very own application section. at least datasource section and sessionFactory. are you using annotations in the hibernate entities?

link publish delete flag offensive edit

answered 2012-03-08 20:28:50 +0800

amina2011 gravatar image amina2011
33 1

here is :

the applicationContext.xml file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<!-- the data source class is recommend to use com.mchange.v2.c3p0.ComboPooledDataSource
in production phase -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/support" />
<property name="user" value="root" />
<property name="password" value="" />
</bean>

<!-- define Hibernate sessionFactory provided by Spring ORM -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- set other Hibernate properties in hibernate.cfg.xml file -->
<property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
</bean>

<!-- define Hibernate sessionFactory provided by Spring -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- for using annotation @Transaction in DAOs -->
<tx:annotation-driven />

<!-- inject relative DAO and Service beans -->
<bean id="companyDAO" class="org.zkoss.model.dao.CompanyDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="companyManager" class="org.zkoss.service.CompanyManagerImpl">
<property name="companyDAO" ref="companyDAO" />
</bean>

<bean id="contactDAO" class="org.zkoss.model.dao.ContactDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="contactManager" class="org.zkoss.service.ContactManagerImpl">
<property name="contactDAO" ref="contactDAO" />
</bean>
</beans>


and the hibernate.cfg.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>

<!-- mapping resources -->
<mapping resource="org/zkoss/model/bean/Company.hbm.xml" />
<mapping resource="org/zkoss/model/bean/Contact.hbm.xml" />
</session-factory>
</hibernate-configuration>

link publish delete flag offensive edit

answered 2012-03-08 21:19:55 +0800

amina2011 gravatar image amina2011
33 1

well it's working now, I still don't know the reason why, but i think it was sth wrong with my tomcat server, i just deleted the server on eclipse and created a new one,
two days looking for a solution , hope it won't apear again.
thank you any way ^_^

link publish delete flag offensive edit

answered 2012-03-09 06:39:45 +0800

blacksensei gravatar image blacksensei
234 2

I'm Glad you got it working because i was scratching my head to find the culprit but everything looks fine, i was even thinking on out of memory but i should have shown on the stacktrace.
Anyway one suggestion though you might want to move information from the hibernate config file (hibernate.cfg.xml) and put it in Spring context under hibernate properties so that you have (when it comes to that) one file for configuring database related stuffs. just saying ,for convenience.

link publish delete flag offensive edit

answered 2012-03-09 23:41:52 +0800

amina2011 gravatar image amina2011
33 1

back again .. unfortunately after i tried to add some changes it doesn't look fine
I want to do the same thing as showed in the small_talk, so i created a new table (User) and i followed the same steps. now i'm getting this

Grave: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to get the default Bean Validation factory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:900)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.HibernateException: Unable to get the default Bean Validation factory
at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:127)
at org.hibernate.cfg.Configuration.applyBeanValidationConstraintsOnDDL(Configuration.java:1677)
at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:1627)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1418)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1829)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 20 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:118)
... 29 more
Caused by: org.hibernate.AssertionFailure: Entity class not found
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:124)
... 34 more
Caused by: java.lang.ClassNotFoundException: org.zkoss.model.bean.User
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:170)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:121)
... 34 more

mars 09, 2012 11:19:05 PM org.apache.catalina.core.StandardContext startInternal
Grave: Error listenerStart
mars 09, 2012 11:19:05 PM org.apache.catalina.core.StandardContext startInternal
Grave: Erreur de démarrage du contexte suite aux erreurs précédentes
mars 09, 2012 11:19:05 PM org.apache.catalina.core.ApplicationContext log
Infos: Closing Spring root WebApplicationContext
mars 09, 2012 11:19:05 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
Grave: The web application registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
mars 09, 2012 11:19:05 PM org.apache.coyote.AbstractProtocol start
Infos: Starting ProtocolHandler ["http-bio-8080"]
mars 09, 2012 11:19:05 PM org.apache.coyote.AbstractProtocol start
Infos: Starting ProtocolHandler ["ajp-bio-8009"]
mars 09, 2012 11:19:05 PM org.apache.catalina.startup.Catalina start
Infos: Server startup in 3665 ms

here are the changes I made in the two configuration files :

int the hibernate file :

<!-- mapping resources -->
<mapping resource="org/zkoss/model/bean/Company.hbm.xml" />
<mapping resource="org/zkoss/model/bean/Contact.hbm.xml" />
<mapping resource="org/zkoss/model/bean/User.hbm.xml" />

in the applicationcontext file

<bean id="companyDAO" class="org.zkoss.model.dao.CompanyDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="companyManager" class="org.zkoss.service.CompanyManagerImpl">
<property name="companyDAO" ref="companyDAO" />
</bean>

<bean id="contactDAO" class="org.zkoss.model.dao.ContactDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="contactManager" class="org.zkoss.service.ContactManagerImpl">
<property name="contactDAO" ref="contactDAO" />
</bean>

<bean id="userDAO" class="org.zkoss.model.dao.UserDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="userManager" class="org.zkoss.service.UserManagerImpl">
<property name="userDAO" ref="userDAO" />
</bean>

every thing else is just like it was, and of course i created the bean, the xml file, the dao, the manager, the manager impl ... etc

concerning your suggesion did you mean that it's better to put all the configuration in one file ?

thanks

link publish delete flag offensive edit

answered 2012-03-10 09:10:04 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2012-03-10 09:22:28 +0800

Be sure to make a Server-Tomcat- 'clean Tomcat work directory' . Sometimes the property or configuration files are not correctly refreshed by deploying in Eclipse.

link publish delete flag offensive edit

answered 2012-03-10 14:47:57 +0800

amina2011 gravatar image amina2011
33 1

thank you, but the "clean Tomcat work directory" didn't help..
now it's hibernate issue , I'm getting this exception

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection

I checked the data source and it looks ok for me:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/support" />
<property name="user" value="root" />
<property name="password" value="" />
</bean>

do you have any idea where this is coming from ??

link publish delete flag offensive edit

answered 2012-03-11 11:23:53 +0800

blacksensei gravatar image blacksensei
234 2

i use this :

        <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >
        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="maxPoolSize" value="${c3p0.max_size}" />
        <property name="minPoolSize" value="${c3p0.min_size}" />
        <property name="checkoutTimeout" value="${c3p0.timeout}" />
        <property name="maxStatements" value="${c3p0.max_statements}" />
        <property name="idleConnectionTestPeriod" value="${c3p0.idle_test_period}" />
        <property name="acquireIncrement" value="${c3p0.acquire_increment}" />
    </bean>
         <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" depends-on="liquibase">
        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            </props>
        </property>
<!-- of course you can use mapping files-->
        <property name="annotatedClasses">
            <list>
                <value>bla.bla.PhoneImpl</value>
            </list>
        </property>
  
 

by the way are you sure your database password is empty for root?

link publish delete flag offensive edit

answered 2012-03-11 12:47:51 +0800

amina2011 gravatar image amina2011
33 1

thanks blacksensei
your configuration could be helpful .. i also faced some problems with the pool's maximum number of connections .. which was in fact the cause that prevented the connexion with the database ..so I set the MySQL variable (max connections ) to a higher number.
anyway it's working again :)

link publish delete flag offensive edit
Your reply
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: 2012-03-08 19:12:21 +0800

Seen: 315 times

Last updated: Mar 11 '12

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