PDA

View Full Version : Spring with MySql.


nitz_tech
Aug 12th, 2004, 02:23 AM
Hello,

I am facing problem configuring the transaction manager for Mysql. Following is the configuration I have made in my spring config file.
===================
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>org.gjt.mm.mysql.Driver</value>
</property>
<property name="url">

<value>jdbc:mysql://server:3306/test</value>

</property>
<property name="username">
<value>testuser</value>
</property>
<property name="password">
<value></value>
</property>
<property name="maxActive">
<value>50</value>
</property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFact oryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>../conf/Provider.hbm.xml</value>
<value>../conf/Role.hbm.xml</value>
<value>../conf/Schedule.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.use_outer_join">true</prop>
<!-- <prop key="hibernate.cglib.use_reflection_optimizer">true</prop> -->
<!-- <prop key="hibernate.default_schema">mysql</prop> -->
<prop key="hibernate.max_fetch_depth">1</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
</props>
</property>
</bean>

====================

I have several other services configured in the config file but they are working fine. At the startup I am calling preInstantiateSingletons() on the factory instance. This function call is giving me an error like:

===================
----- Root Cause -----
java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.ja va:1647)
at java.lang.Class.getDeclaredMethods(Class.java:1131 )
at java.beans.Introspector$1.run(Introspector.java:11 26)
at java.security.AccessController.doPrivileged(Native Method)
at java.beans.Introspector.getPublicDeclaredMethods(I ntrospector.java:1124)
at java.beans.Introspector.getTargetMethodInfo(Intros pector.java:989)
at java.beans.Introspector.getBeanInfo(Introspector.j ava:370)
at java.beans.Introspector.getBeanInfo(Introspector.j ava:144)
at org.springframework.beans.CachedIntrospectionResul ts.<init>(CachedIntrospectionResults.java:85)
at org.springframework.beans.CachedIntrospectionResul ts.forClass(CachedIntrospectionResults.java:62)
at org.springframework.beans.BeanWrapperImpl.setWrapp edInstance(BeanWrapperImpl.java:190)
at org.springframework.beans.BeanWrapperImpl.<init>(BeanWrapperImpl.java:168)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:184)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:172)
at com.imc.hfehr.util.StartupManager.init(StartupMana ger.java:102)
at org.apache.struts.action.ActionServlet.initModuleP lugIns(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.init(Action Servlet.java:473)
at javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1029)
at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:862)
at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:4013)
at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4357)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1083)
at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:789)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1083)
at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:478)
at org.apache.catalina.core.StandardService.start(Sta ndardService.java:480)
at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2313)
at org.apache.catalina.startup.Catalina.start(Catalin a.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:284)
at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:422)

===================

Can anybody help me out with this ??

Thanx in advance,


Nitin

twicet
Aug 12th, 2004, 03:15 AM
This exception "java.lang.NoClassDefFoundError: javax/transaction/TransactionManager" usually indicates that you need jta.jar in your classpath. Do you have it?

nitz_tech
Aug 12th, 2004, 04:47 AM
Yes you are right buddy. It was missing. I added it to my lib folder and in my project classpath.

Thanx for the help

Nitin.

davison
Aug 12th, 2004, 08:30 AM
<value>org.gjt.mm.mysql.Driver</value>
Note too just for info that this driver is very old now. The com.mysql driver should really be used. See http://www.mysql.com/products/connector/j/

Martin Kersten
Aug 12th, 2004, 07:06 PM
This driver is not old. It is provided by all new connector releases. It is just the name used before the connector-api was adopted by mysql AB. But anyways you are right. Using the com.mysql class is more readable but you can use both classes anyways. Doesn't matter, just a question of style.

trisberg
Aug 12th, 2004, 11:29 PM
You are correct, the org.gjt.mm.mysql.Driver is now just a wrapper extending com.mysql.jdbc.Driver so either way you are using the same driver - just different names.

nitz_tech
Aug 13th, 2004, 05:38 AM
Thanks guys,

I have another question running on my mind. I am using the service "org.springframework.orm.hibernate.HibernateTransac tionManager" and passing the "org.springframework.orm.hibernate.LocalSessionFact oryBean" reference. This transaction manager belongs to the Spring framework. But the exception said that jta.jar was missing which has the actual javax.transaction.TransactionManager. Is it that Spring Framework has tried to add a layer of additional services over the core jta api to support the list of features that the framework has. What are the services that are related to the Transactions.

bpolka
Aug 13th, 2004, 11:05 AM
Thanks guys,

I have another question running on my mind. I am using the service "org.springframework.orm.hibernate.HibernateTransac tionManager" and passing the "org.springframework.orm.hibernate.LocalSessionFact oryBean" reference. This transaction manager belongs to the Spring framework. But the exception said that jta.jar was missing which has the actual javax.transaction.TransactionManager. Is it that Spring Framework has tried to add a layer of additional services over the core jta api to support the list of features that the framework has. What are the services that are related to the Transactions.

Hibernate requires that jar to be on classpath, so it probably has very little to do with Spring.