Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: declarative transaction via JDBC

  1. #11
    Join Date
    Sep 2004
    Location
    Winterthur, Switzerland
    Posts
    58

    Default

    Question: how are you testing?
    The reason i am asking = the Transactional Proxy - your case "pmis1" - needs to be referenced, where the bean "userLogic", if you want transactional behaviour.

    In the following a TestCase, which works fine ... eventually selecting from the database manually, to check if anything is there ;-)
    So the connection stuff was really misleading, sorry about that...
    The testcase works both against SingleConnectionDataSource and DriverManagerDataSource.


    import junit.framework.TestCase;

    import org.springframework.context.support.FileSystemXmlA pplicationContext;
    import org.springframework.dao.DataAccessException;

    public class TestInsert extends TestCase
    {

    private FileSystemXmlApplicationContext ctx;
    private JdbcUser userLogic;
    /*
    * @see TestCase#setUp()
    */
    protected void setUp() throws Exception
    {
    super.setUp();
    String path[] = {"/war/WEB-INF/applicationContext.xml"};
    ctx = new FileSystemXmlApplicationContext(path);
    ctx.refresh();
    Object obj = ctx.getBean("pmis1"); // and not userLogic
    if (!(obj instanceof JdbcUser))
    {
    throw new Exception("Bean Configuration wrong");
    }
    userLogic = (JdbcUser) obj;
    }

    public void testInsert() throws Exception
    {
    try {
    final User aUser = new User();
    aUser.setName("Some name");
    aUser.setPasswd("Some Passwd");
    userLogic.storeUsers(aUser);
    fail("Unexpected");
    } catch (DataAccessException e)
    {
    System.out.println(e.toString());
    // Ok, but test some more
    }
    }

    /*
    * @see TestCase#tearDown()
    */
    protected void tearDown() throws Exception
    {
    super.tearDown();
    ctx = null;
    userLogic = null;
    }

    }

  2. #12
    Join Date
    Sep 2004
    Location
    Winterthur, Switzerland
    Posts
    58

    Default

    BTW: the test output looked as follows
    <snip>
    [junit] 01.11.2004 14:52:14 org.springframework.jdbc.object.RdbmsOperation compile
    [junit] INFO: RdbmsOperation with SQL [INSERT INTO testusers VALUES(?,?)] compiled
    [junit] 01.11.2004 14:52:14 org.springframework.jdbc.support.SQLErrorCodesFact ory getErrorCodes
    [junit] INFO: Looking up default SQLErrorCodes for DataSource
    [junit] 01.11.2004 14:52:14 org.springframework.jdbc.support.SQLErrorCodesFact ory getErrorCodes
    [junit] INFO: Database product name found in cache for DataSource [org.springframework.jdbc.datasource.DriverManagerD ataSource@9be79a]. Name is 'Oracle'.
    [junit] 01.11.2004 14:52:14 org.springframework.jdbc.object.RdbmsOperation compile
    [junit] INFO: RdbmsOperation with SQL [INSERT INTO testusers1 VALUES(?,?)] compiled
    [junit] 01.11.2004 14:52:14 org.springframework.jdbc.support.SQLErrorCodeSQLEx ceptionTranslator logTranslation
    [junit] WARNUNG: Translating SQLException with SQLState '42000' and errorCode '942' and message [ORA-00942: table or view does not exist
    [junit] ]; SQL was [INSERT INTO testusers1 VALUES(?,?)] for task [executing PreparedStatementCallback [PreparedStatementCreatorFactory.PreparedStatementC reatorImpl: sql=[INSERT INTO testusers1 VALUES(?,?)]: params=[Some name,Some Passwd]]]
    [junit] .From prgm: org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [INSERT INTO testusers1 VALUES(?,?)] in task 'executing PreparedStatementCallback [PreparedStatementCreatorFactory.PreparedStatementC reatorImpl: sql=[INSERT INTO testusers1 VALUES(?,?)]: params=[Some name,Some Passwd]]'; nested exception is java.sql.SQLException: ORA-00942: table or view does not exist
    [junit] 01.11.2004 14:52:14 org.springframework.transaction.interceptor.Transa ctionInterceptor onThrowable
    [junit] INFO: Invoking rollback for transaction on method 'storeUsers' in class [JdbcUser] due to throwable [org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [INSERT INTO testusers1 VALUES(?,?)] in task 'executing PreparedStatementCallback [PreparedStatementCreatorFactory.PreparedStatementC reatorImpl: sql=[INSERT INTO testusers1 VALUES(?,?)]: params=[Some name,Some Passwd]]'; nested exception is java.sql.SQLException: ORA-00942: table or view does not exist
    [junit] ]
    [junit] 01.11.2004 14:52:14 org.springframework.transaction.support.AbstractPl atformTransactionManager rollback
    [junit] INFO: Initiating transaction rollback
    [junit] org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [INSERT INTO testusers1 VALUES(?,?)] in task 'executing PreparedStatementCallback [PreparedStatementCreatorFactory.PreparedStatementC reatorImpl: sql=[INSERT INTO testusers1 VALUES(?,?)]: params=[Some name,Some Passwd]]'; nested exception is java.sql.SQLException: ORA-00942: table or view does not exist
    [junit] Time: 1,344
    [junit] OK (1 test)
    <snip>

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  3. Transaction Management
    By caverns in forum Data
    Replies: 3
    Last Post: Mar 8th, 2005, 06:38 AM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •