Results 1 to 10 of 10

Thread: Advance Problem - Datanucleus JDO Integration into STS/Tomcat won't work

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Posts
    15

    Exclamation Advance Problem - Datanucleus JDO Integration into STS/Tomcat won't work

    Hi All,

    I have for the last few days been trying to solve this challenging problem, can anyone help me?

    I have downloaded the Datanucleus JDO tutorial and it works fine the standard Java standalone environment. However, upon integrating it with my STS/Spring Webflow/Tomcat application, a NULL pointer exception is thrown as it progresses through the Products list.

    The relevant part of my code is as follows:

    Code:
    // Usual setup and then...
    
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
            
    try {
    
       tx.begin();            
                
       LOGGER.debug("Executing Query for ALL Products...");
       Query q=pm.newQuery("SELECT FROM " + Product.class.getName());                        
                
       List<Product> products = (List<Product>)q.execute();
       Iterator<Product> iter = products.iterator();
    
       // Problem is here... upon the second iteration it should exit loop, but for some reason it doesn't...
       while (iter.hasNext()) {
    
          Product p = iter.next();                
          LOGGER.debug(">  " + p); // upon second iteration, a NULL pointer exception is thrown
                    
          if (p instanceof Book) {
    
             Book b = (Book)p;
             b.setDescription("This book has been reduced in price!");
          }
       }
    
       tx.commit();
    
       } finally {
    
          if (tx.isActive()) {
             tx.rollback();
          }
    
          pm.close();
       }
    
    LOGGER.debug("Query completed.");
    
    // And so on...
    ...Upon iterating through the Products list, it displays the first product (as there is only one product), but for some reason when the code loops back up to iter.hasNext(), it should exit, however it tries to receive the next (non-existent) product in the list. As mentioned above, in the standalone Java version, this works fine without exceptions!!

    Any ideas or directions will be most helpful as I have run out of ideas on how to fix this problem.

    For those who may want to see the exception report:

    Code:
    07-Jul-2012 21:53:28 org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [accountapp] in context with path [/accountapp] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@1c5a33b targetAction = [EvaluateAction@5facbd expression = accountappFlowActions.submitGetAccount(requestParameters.getAccountId, manager), resultExpression = account], attributes = map[[empty]]] in state 'accountList' of flow 'adminmenu' -- action execution attributes were 'map[[empty]]'] with root cause
    java.lang.NullPointerException
    Please note that both the standalone Java application and the Spring Webflow/Tomcat application used Java 1.6.
    Last edited by jbolat; Jul 8th, 2012 at 04:21 AM. Reason: Extra Info

  2. #2

    Default

    The "exception report" omits to include the NPE and its stack trace, hence hardly of any use. Obviously the DataNucleus log would tell you all that its doing, and then you can compare it with the same log for the non-Tomcat case and see where you have the configuration different.
    -Andy
    DataNucleus - Standardised persistence, multiple datastores

  3. #3
    Join Date
    Jul 2012
    Location
    Pittsburg,PA
    Posts
    2

    Default

    Quote Originally Posted by jbolat View Post
    ...Upon iterating through the Products list, it displays the first product (as there is only one product), but for some reason when the code loops back up to iter.hasNext(), it should exit, however it tries to receive the next (non-existent) product in the list. As mentioned above, in the standalone Java version, this works fine without exceptions!!

    Any ideas or directions will be most helpful as I have run out of ideas on how to fix this problem.
    How do you know there is only one product ? Do you mean there is just one record in the table of just one object in the collection ?
    Also when you say "standalone java version" you mean a JUnit invoking the above code ?
    Regards
    AbhishekD

  4. #4
    Join Date
    Apr 2012
    Posts
    15

    Default

    Thanks to all for replying, much appreciated it.

    The problem was that upon creating an automated .jdo file for the persisted classes using the Datanucleus plugin for STS (as instructed in the tutorial), this somehow turned out to be in conflict with the .orm file provided with the sample JDO tutorial. Hence, upon removing the .jdo file, it worked!

    Andy: I know STS is based on Eclipse and Datanucleus plugin should work all well, however, I seem to have problems with CreateSchema via the Datanucleus menu whereas strangely when using "ant createschema" via the command window, it works fine. My STS version is 2.7.1 and my backend database is MySQL 5.5. Here is the error exception report taken from datanucleus.log file:

    Code:
    21:26:47,586 (main) ERROR [DataNucleus.Datastore] - Error thrown executing CREATE TABLE `INVENTORY`
    (
        `NAME` VARCHAR(256) BINARY NOT NULL,
        CONSTRAINT `INVENTORY_PK` PRIMARY KEY (`NAME`)
    ) ENGINE=INNODB : Index column size too large. The maximum column size is 767 bytes.
    java.sql.SQLException: Index column size too large. The maximum column size is 767 bytes.
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2677)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2627)
    	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:841)
    	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:681)
    	at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
    	at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
    	at org.datanucleus.store.rdbms.table.AbstractTable.executeDdlStatement(AbstractTable.java:761)
    	at org.datanucleus.store.rdbms.table.AbstractTable.executeDdlStatementList(AbstractTable.java:712)
    	at org.datanucleus.store.rdbms.table.AbstractTable.create(AbstractTable.java:426)
    	at org.datanucleus.store.rdbms.table.AbstractTable.exists(AbstractTable.java:489)
    	at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.performTablesValidation(RDBMSStoreManager.java:2576)
    	at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.addClassTablesAndValidate(RDBMSStoreManager.java:2388)
    	at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.run(RDBMSStoreManager.java:2031)
    	at org.datanucleus.store.rdbms.AbstractSchemaTransaction.execute(AbstractSchemaTransaction.java:113)
    	at org.datanucleus.store.rdbms.RDBMSStoreManager.createSchema(RDBMSStoreManager.java:3157)
    	at org.datanucleus.store.schema.SchemaTool.createSchema(SchemaTool.java:457)
    	at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:387)
    
    21:26:47,587 (main) ERROR [DataNucleus.Datastore.Schema] - An exception was thrown while adding/validating class(es) : Index column size too large. The maximum column size is 767 bytes.
    java.sql.SQLException: Index column size too large. The maximum column size is 767 bytes.
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2677)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2627)
    	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:841)
    	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:681)
    	at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
    	at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
    	at org.datanucleus.store.rdbms.table.AbstractTable.executeDdlStatement(AbstractTable.java:761)
    	at org.datanucleus.store.rdbms.table.AbstractTable.executeDdlStatementList(AbstractTable.java:712)
    	at org.datanucleus.store.rdbms.table.AbstractTable.create(AbstractTable.java:426)
    	at org.datanucleus.store.rdbms.table.AbstractTable.exists(AbstractTable.java:489)
    	at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.performTablesValidation(RDBMSStoreManager.java:2576)
    	at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.addClassTablesAndValidate(RDBMSStoreManager.java:2388)
    	at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.run(RDBMSStoreManager.java:2031)
    	at org.datanucleus.store.rdbms.AbstractSchemaTransaction.execute(AbstractSchemaTransaction.java:113)
    	at org.datanucleus.store.rdbms.RDBMSStoreManager.createSchema(RDBMSStoreManager.java:3157)
    	at org.datanucleus.store.schema.SchemaTool.createSchema(SchemaTool.java:457)
    	at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:387)
    
    ...and so on...
    Could you give me any directions with regards to this problem? Thanks.

  5. #5

    Default

    Why are you trying to create a VARCHAR(256) column? Would have thought 255 much better for RDBMS (and MySQL is objecting there, due to that). There's some persistence property to set the default string length to that.
    -Andy
    DataNucleus - Standardised persistence, multiple datastores

  6. #6
    Join Date
    Apr 2012
    Posts
    15

    Default

    Dear Andy: I am using the same tutorial sample code that I downloaded from the official Datanucleus website (http://www.datanucleus.org/products/.../tutorial.html & http://www.datanucleus.org/products/...pse/index.html). The same mapping configuration and java files are used and the only difference is that when I invoke the CreateSchema via the ant script (provided by the tutorial) it works, however, invoking the CreateSchema via the Datanucleus sub-menu (as also instructed in the tutorial) from within STS, I get the above error? I was wondering if there is a bug with CreateShema Eclipse plugin as I am using STS (even though STS is based on Eclipse 3.7.0) or if there is a problem directly with STS? Another twist to this scenario is that, even though I have set the flags for MySQL to accept column sizes larger than 767 bytes, I still get the same error message as in my earlier post!

  7. #7

    Default

    No you're not using the tutorial we provide ... as can be seen here http://datanucleus.svn.sourceforge.n...62&view=markup for HSQL (you have to add an equivalent file for MySQL if you use MySQL) that the length for Inventory.name is defined as 100.

    JDO spec, and JDO docs for DataNucleus define such concepts as column length very well; I'd suggest reading them
    -Andy
    DataNucleus - Standardised persistence, multiple datastores

Tags for this Thread

Posting Permissions

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