Announcement Announcement Module
Collapse
No announcement yet.
Persistence setup with DB2/400 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Persistence setup with DB2/400

    I have an iSeries with DB2/400 that I want to setup with Roo. I did the initial setup of Roo's persistence using --database HYPERSONIC_IN_MEMORY --provider HIBERNATE. That works fine. I was able to create an entity class called ZipSystem, a controller class called ZipSystemController and verify that it works.

    Now I'm trying to use my DB2/400 as my database. I am using JT400 6.7 and I know I need to use com.ibm.as400.access.AS400JDBCDriver as the driver class. I've updated the database.properties file with the correct url, username and password. I've updated the persistence.xml file to use org.hibernate.dialect.DB2400Dialect. The application loads ok, but whenever I try to list the existing ZipSystems or create a new one, I get an SQLGrammarException. I get "could not execute query; nested exception is javax.persistence.PersistenceException" when listing, or I get "could not insert; nested exception is javax.persistence.PersistenceException".

    I've left the applicationContext.xml file as the defaults generated by Roo. So not sure what else I need to update/add in order to get it working.

  • #2
    I managed to fix this problem by creating my own Entity Manager Factory from javax.persistence.Persistence in my applicationContext.xml. I only have one datasource that is managed by my application and not the container like Roo auto generates. I also passed the persistence unit name and map of properties for driver, url, user and password to the factory method that returns the EntityManagerFactory.

    My bean definition looks like this:
    Code:
    <bean id="entityManagerFactory" class="javax.persistence.Persistence" factory-method="createEntityManagerFactory">
    		<constructor-arg value="persistenceUnit" />
    		<constructor-arg>
    			<map key-type="java.lang.String" value-type="java.lang.String">
    				<entry key="javax.persistence.jdbc.driver" value="${database.driverClassName}" />
    				<entry key="javax.persistence.jdbc.url" value="${database.url}" />
    				<entry key="javax.persistence.jdbc.user" value="${database.username}" />
    				<entry key="javax.persistence.jdbc.password" value="${database.password}" />
    			</map>
    		</constructor-arg>
        </bean>
    My persistence.xml looks like this now:
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"
    			 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    			 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    
        <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect"/>
                <property name="hibernate.show_sql" value="true"/>
            </properties>
        </persistence-unit>
    </persistence>

    Comment


    • #3
      What was the format for the url you used in your properties file.

      I have tried jdbc:as400:<server> and jdbc:as400://<server>

      I have also played with adding libraries=,translate binary=true, etc.

      Also, can you post which driver you chose. I am using com.ibm.as400.access.AS400JDBCDataSource, but it keeps telling me no suitable driver found, but it is there in the pom.xml.

      Thanks

      Comment


      • #4
        I have the URL setup as jdbc\:as400\://host

        I am using com.ibm.as400.access.AS400JDBCDriver for the driver.

        Comment


        • #5
          Actually if you download Roo 1.1.0.M3, they've added support for DB2400 in the persistence setup command. It should take care of setting up persistence.xml correctly, you just need to enter the actual host name and username/password.

          Comment


          • #6
            how do you specify a specific library to use?

            Comment


            • #7
              I don't typically. I set that in the Entity class using the @Table annotation like this:


              @Table(name = "FILE", schema = "LIBRARY")

              Comment


              • #8
                Thanks for your help...

                I don't think using the annotations will work for me to specify the schema as they are different between production and the development database. Not my choice, but I will give this a shot and see if there is someway i can configure it at runtime.

                I will download the latest milestone for roo and give that a shot.

                Comment


                • #9
                  Makes sense. We have test and production libraries as well. I typically set the schema in the annotation to the test library during development, and then change it to the production library when I'm ready to release the app.

                  Comment


                  • #10
                    this exception makes it sound like it can't find the jt400.jar

                    Code:
                    java.sql.SQLException: No suitable driver found for jdbc:as400://knl400s
                    	at java.sql.DriverManager.getConnection(DriverManager.java:640)
                    	at java.sql.DriverManager.getConnection(DriverManager.java:169)
                    	at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
                    	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:114)
                    	at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
                    	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
                    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
                    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
                    	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
                    	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
                    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
                    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                    	at java.lang.reflect.Method.invoke(Method.java:616)
                    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:145)
                    	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:983)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:879)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
                    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
                    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
                    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
                    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
                    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
                    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
                    	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
                    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
                    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
                    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
                    	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333)
                    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
                    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
                    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
                    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
                    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
                    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
                    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
                    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
                    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
                    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
                    	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
                    	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
                    	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
                    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
                    	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
                    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
                    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
                    	at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
                    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                    	at java.lang.reflect.Method.invoke(Method.java:616)
                    	at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
                    	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

                    Comment


                    • #11
                      You need JTOpen on your classpath. Roo 1.1.0.M3 will add it automatically when you use DB2400 in the persistence setup command.

                      <dependency>
                      <groupId>net.sf.jt400</groupId>
                      <artifactId>jt400</artifactId>
                      <version>6.7</version>
                      </dependency>

                      Comment


                      • #12
                        I have it added, but for some reason it can't resolve 6.7. I have it using 6.6.

                        Comment


                        • #13
                          That's odd. Version 6.6 should still work just fine, 6.7 is the latest stable release. I have no problem resolving it though.

                          Comment


                          • #14
                            i can browse the repo and see it there, when I try to resolve it from within STS, it fails. Yet i can resolve 6.6 and every other external resource.

                            But it is also as if 6.6 is not being found on the classpath when the integration tests are being executed.

                            Comment


                            • #15
                              Sounds like a classpath issue. I'm not experiencing any of those problems.

                              Comment

                              Working...
                              X