Announcement Announcement Module
Collapse
No announcement yet.
Spring 2.0 and Maven 2 problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 2.0 and Maven 2 problem

    Hi All,

    In my earlier post here, I described about the problem that I was facing upgrading the spring jar version. Probably because of a long post I didn't receive any reply to that, now I tried only with the example at http://blog.springframework.com/mark...-in-spring-20/

    I tried this example as a simple eclipse project and as a maven project.

    Following are my observations:

    1. Simple eclipse project
    -------------------------
    - spring 2.0 (spring, spring-mock,spring-jpa)
    - toplink (v2-b22)
    - commons-logging-1.1
    - log4j-1.2.12
    - junit-3.8.1
    - hsqldb-1.8.0.4

    * Test run successful

    2. Maven project (with maven-2.0.4)
    -----------------------------------
    - all the jars remain same

    * Test case fails

    pom.xml for this project is as:
    Code:
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.mycompany.dao</groupId>
    
        <artifactId>markfisher-blog-example</artifactId>
    
        <packaging>jar</packaging>
    
        <name>DAO Spring-JPA Test</name>
    
        <version>2.0.01-SNAPSHOT</version>
    
        <description>
            DAO with Spring JPA
        </description>
    
        <build>
            <defaultGoal>package</defaultGoal>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <inherited>true</inherited>
                        <configuration>
                            <source>1.5</source>
                            <target>1.5</target>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    
        <dependencies>
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.1</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring</artifactId>
                <version>2.0</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jpa</artifactId>
                <version>2.0</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-mock</artifactId>
                <version>2.0</version>
            </dependency>
            <dependency>
           	    <groupId>oracle.toplink.essentials</groupId>
                <artifactId>toplink-essentials</artifactId>
                <version>1.1</version>
            </dependency>
            <dependency>
           	    <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.12</version>
            </dependency>
            <dependency>
                <groupId>hsqldb</groupId>
                <artifactId>hsqldb</artifactId>
                <version>1.8.0.4</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </project>

    I got following exception when tried to build it:

    Code:
    -------------------------------------------------------------------------------
    Test set: blog.jpa.dao.JpaRestaurantDaoTestCase
    -------------------------------------------------------------------------------
    Tests run: 10, Failures: 0, Errors: 10, Skipped: 0, Time elapsed: 22.765 sec <<< FAILURE!
    testFindByIdWhereRestaurantExists(blog.jpa.dao.JpaRestaurantDaoTestCase)  Time elapsed: 22.578 sec  <<< ERROR!
    org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [insert into address (id, street_number, street_name) values (1, 10, 'Main Street')]; nested exception is java.sql.SQLException: Table not found in statement [insert into address]
    Caused by: java.sql.SQLException: Table not found in statement [insert into address]
    	at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    	at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
    	at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
    	at org.springframework.jdbc.core.JdbcTemplate$1ExecuteStatementCallback.doInStatement(JdbcTemplate.java:336)
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:310)
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:343)
    	at blog.jpa.dao.JpaRestaurantDaoTestCase.onSetUpInTransaction(JpaRestaurantDaoTestCase.java:23)
    	at org.springframework.test.AbstractTransactionalSpringContextTests.onSetUp(AbstractTransactionalSpringContextTests.java:170)
    	at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:77)
    	at junit.framework.TestCase.runBare(TestCase.java:125)
    	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.access$001(AbstractAnnotationAwareTransactionalTests.java:44)
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests$1.run(AbstractAnnotationAwareTransactionalTests.java:112)
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTest(AbstractAnnotationAwareTransactionalTests.java:177)
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTestTimed(AbstractAnnotationAwareTransactionalTests.java:150)
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runBare(AbstractAnnotationAwareTransactionalTests.java:108)
    	at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:160)
    	at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:239)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	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.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:210)
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:135)
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:160)
    	at org.apache.maven.surefire.Surefire.run(Surefire.java:81)
    	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.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:182)
    	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:743)
    Same exception was thrown for all the test methods.

    In my earlier post here, I mentioned using aspects with the aforesaid example, and had a maven project (maven version 2.0.4), where I was using LTW as well as CTW with spring-2.0-rc2 jars(with an earlier build version of toplink), everything worked fine,(I am still stuck with the problem of upgrading the jars from RC2 to 2.0) but the same environment is not supported in this case!

    Please help me in finding out the reason for this behavior.

    Thanks,
    Jayant

  • #2
    The exception indicates that the db schema is not up to date - the address table is missing. I haven't tried Mark's blog so can you post your webapp? Btw, can try running without maven - several users reported problems lately which were caused by 'hidden' dependencies which were pulled by maven and used instead of the one mentioned by the user (this might be or not the case here).
    You mention also a problem with a LTW - can you be more precise? The exception above is caused by the database structure not the way classes are loaded.

    Comment


    • #3
      Thanks Costin for replying to this post. I am attaching the code which I am using right now. For the simple eclipse project everything works out to be fine. As pointed out by you that the ADDRESS table is not present, what I figured out was that when I try executing the test case (of the maven setup), the generateDdl doesn't work and that's the source of the problem. I simply cannot understand why is this happening.

      Following is the console output of both the setups:
      1. For simple eclipse project
      Code:
      2006-11-13 11:54:05,375 INFO [org.springframework.jdbc.datasource.DriverManagerDataSource] - <Loaded JDBC driver: org.hsqldb.jdbcDriver>
      [TopLink Config]: 2006.11.13 11:54:05.921--ServerSession(25352765)--Thread(Thread[main,5,main])--The alias name for the entity class [class blog.jpa.domain.Address] is being defaulted to: Address.
      [TopLink Config]: 2006.11.13 11:54:05.953--ServerSession(25352765)--Thread(Thread[main,5,main])--The table name for entity [class blog.jpa.domain.Address] is being defaulted to: ADDRESS.
      [TopLink Config]: 2006.11.13 11:54:05.984--ServerSession(25352765)--Thread(Thread[main,5,main])--The column name for element [private long blog.jpa.domain.Address.id] is being defaulted to: ID.
      [TopLink Config]: 2006.11.13 11:54:06.015--ServerSession(25352765)--Thread(Thread[main,5,main])--The alias name for the entity class [class blog.jpa.domain.Restaurant] is being defaulted to: Restaurant.
      ........
      ........
      11:49:50.343--ServerSession(25352765)--Thread(Thread[main,5,main])--file:/D:/Jayant/codes/markfisher-blog-example-eclipse/bin/-SpringJpaGettingStarted login successful
      [TopLink Fine]: 2006.11.13 11:49:50.375--ServerSession(25352765)--Connection(30340343)--Thread(Thread[main,5,main])--CREATE TABLE RESTAURANT_ENTREE (Restaurant_ID NUMERIC(19) NOT NULL, ENTREE_ID NUMERIC(19) NOT NULL, PRIMARY KEY (Restaurant_ID, ENTREE_ID))
      [TopLink Fine]: 2006.11.13 11:49:50.390--ServerSession(25352765)--Connection(13748088)--Thread(Thread[main,5,main])--CREATE TABLE ENTREE (ID NUMERIC(19) NOT NULL, NAME VARCHAR(255), VEGETARIAN TINYINT, PRIMARY KEY (ID))
      [TopLink Fine]: 2006.11.13 11:49:50.390--ServerSession(25352765)--Connection(8303462)--Thread(Thread[main,5,main])--CREATE TABLE RESTAURANT (ID NUMERIC(19) NOT NULL, NAME VARCHAR(255), ADDRESS_ID NUMERIC(19), PRIMARY KEY (ID))
      [TopLink Fine]: 2006.11.13 11:49:50.390--ServerSession(25352765)--Connection(3403998)--Thread(Thread[main,5,main])--CREATE TABLE ADDRESS (ID NUMERIC(19) NOT NULL, STREET_NUMBER INTEGER, STREET_NAME VARCHAR(255), PRIMARY KEY (ID))
      [TopLink Fine]: 2006.11.13 11:49:50.390--ServerSession(25352765)--Connection(12644844)--Thread(Thread[main,5,main])--CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT NUMERIC(38), PRIMARY KEY (SEQ_NAME))
      For maven setup
      Code:
      2006-11-13 11:55:16,875 INFO [org.springframework.jdbc.datasource.DriverManagerDataSource] - <Loaded JDBC driver: org.hsqldb.jdbcDriver>
      [TopLink Config]: 2006.11.13 11:52:12.500--ServerSession(3874052)--Connection(30533424)--Thread(Thread[main,5,main])--Connected: jdbc:hsqldb:mem:testdb
      	User: SA
      	Database: HSQL Database Engine  Version: 1.8.0
      	Driver: HSQL Database Engine Driver  Version: 1.8.0
      [TopLink Info]: 2006.11.13 11:52:12.531--ServerSession(3874052)--Thread(Thread[main,5,main])--file:/D:/Jayant/codes/markfisher-blog-example-maven/target/test-classes/-SpringJpaGettingStarted login successful
      2006-11-13 11:52:12,609 INFO [blog.jpa.dao.JpaRestaurantDaoTestCase] - <Began transaction (1): transaction manager [org.springframework.orm.jpa.JpaTransactionManager@71dc3d]; default rollback = true>
      2006-11-13 11:52:12,640 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]>
      Notice the entities being mapped to respective tables and the create stmts in the first case, this seems to the source of the problem in the second case but the reason is still not known.

      Regarding LTW, in this case it is not required, I had written this wrt to this post of mine.

      Please take out some time and have a look at this problem.

      Thanks,
      Jayant

      Comment


      • #4
        Did you ever figure out the issue? I'm seeing the same thing.

        Comment

        Working...
        X