PDA

View Full Version : Does DB2400 work with Spring?



wskent
Mar 13th, 2008, 04:55 PM
I have DB2400 working with Hibernate. I have not seen a working example of using DB2400 with Spring 2.x & Hibernate 3.x . Has anyone got a working example using Spring 2.x and Hibernate 3.x with a DB2400 database?
Here is what I have in my test applicationContext.xml file -
<bean
class="org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor" />

<bean id="personService" class="quickstart.service.PersonServiceImpl" />

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVen dorAdapter">
<!--
<property name="database" value="DB2400" />
<property name="showSql" value="true" />
-->
<property name="hibernateProperties">
<props>
<prop key="show_sql">true</prop>
<prop key="dialect">org.hibernate.dialect.DB2400Dialect</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
</props>
</property>
</bean>
</property>
</bean>

<bean id="dataSource"
class="com.ibm.as400.access.AS400JDBCConnectionPoolDataSo urce">
<property name="driverClassName" value="com.ibm.as400.access.AS400JDBCDriver" />
<property name="url" value="jdbc:as400://GDEV/LIBRARY;translate binary=true;" />
<property name="username" value="USER" />
<property name="password" value="PASSWORD" />
</bean>

<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

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

<bean id="personAction" scope="prototype"
class="quickstart.action.PersonAction">
<constructor-arg ref="personService" />
</bean>

I get the following error when deploying to JBoss -
16:53:58,641 INFO [STDOUT] ERROR - Log4JLogger.error(119) | Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.transaction.interceptor.Trans actionAttributeSourceAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.Transa ctionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'driverClassName' of bean class [com.ibm.as400.access.AS400JDBCConnectionPoolDataSo urce]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'driverClassName' of bean class [com.ibm.as400.access.AS400JDBCConnectionPoolDataSo urce]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'driverClassName' of bean class [com.ibm.as400.access.AS400JDBCConnectionPoolDataSo urce]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'driverClassName' of bean class [com.ibm.as400.access.AS400JDBCConnectionPoolDataSo urce]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'driverClassName' of bean class [com.ibm.as400.access.AS400JDBCConnectionPoolDataSo urce]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'driverClassName' of bean class [com.ibm.as400.access.AS400JDBCConnectionPoolDataSo urce]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

travism
Mar 17th, 2008, 09:37 AM
We have a large volume web app that has been using Spring 1.* and 2.* and Hibernate 3.* on MAINFRAME z/os 390 Db2 for two years now. If they support 390 db2 I am sure they support the 400 db2.

It did take me the better part of two days to get our unit test's applicationContext working properly with db2connect. I had problems figuring out the right driver to use. We ended up using COM.ibm.db2.jdbc.app.DB2Driver which connects through db2 connect (jdbc 2.0 drivers though). Looks like you are using a type4 driver though. My guess is you aren't using the right driver. [Edit this type4 driver worked for us, it was just trial and error to find the right one: com.ibm.db2.jcc.DB2Driver]

IBM might have some redbooks out there that can help you more than I tried. One thing I learned is that if you're mainframe db2 make sure the docs you use explicitly say mainframe because the product is considerably different between the "mainframe db2" and "LUW db2"

hth.

wpoitras
Mar 17th, 2008, 10:00 AM
According to your stacktrace "driverClassName" is not a writable property of your datasource. Taking a look at the javadoc for "AS400JDBCConnectionPoolDataSource" shows this to be true. It takes the name of an server as a constructor argument, and can optionally take some other parameters. Either you need another dataSource or you need to use other parameters.

I'd suggest creating a simple test program that constructs a DataSource programatically so you can fiddle with what class and parameters work for you before translating that into a Spring context. As you noticed the Spring context stack traces are difficult to read.