Announcement Announcement Module
No announcement yet.
Spring 2.0 and Maven 2 problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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

    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-

    * 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:
    <project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
        <name>DAO Spring-JPA Test</name>
            DAO with Spring JPA

    I got following exception when tried to build it:

    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(
    	at org.springframework.jdbc.core.JdbcTemplate.execute(
    	at org.springframework.jdbc.core.JdbcTemplate.execute(
    	at blog.jpa.dao.JpaRestaurantDaoTestCase.onSetUpInTransaction(
    	at org.springframework.test.AbstractTransactionalSpringContextTests.onSetUp(
    	at org.springframework.test.AbstractSingleSpringContextTests.setUp(
    	at junit.framework.TestCase.runBare(
    	at org.springframework.test.ConditionalTestCase.runBare(
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.access$001(
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests$
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTest(
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTestTimed(
    	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runBare(
    	at org.springframework.test.jpa.AbstractJpaTests.runBare(
    	at org.springframework.test.jpa.AbstractJpaTests.runBare(
    	at junit.framework.TestResult$1.protect(
    	at junit.framework.TestResult.runProtected(
    	at junit.framework.TestSuite.runTest(
    	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(
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(
    	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(
    	at org.apache.maven.surefire.booter.SurefireBooter.main(
    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.


  • #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.


    • #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
      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] 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
      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 [[email protected]]; 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.



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