Announcement Announcement Module
Collapse
No announcement yet.
Advance Problem - Datanucleus JDO Integration into STS/Tomcat won't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 04:21 AM. Reason: Extra Info

  • #2
    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 ?

    Comment


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

      Comment


      • #4
        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!

        Comment


        • #5
          Andy: Yes, you are right, my backend database is MySQL and the tutorial uses a HSQL. And yes, you are right again, the column size in the tutorial mapping file is set to 100, but so is also my adapted package-mysql.orm, that's why it works when invoking the ant script provided by the tutorial for schema creation. However, when invoking CreateSchema from Datanucleus sub-menu from STS, somehow it does not recognise creating the schema in accordance to the package-mysql.orm file. Is there a reason for this or does the CreateSchema only recognise .jdo files for object mappings?

          For your information, my package-mysql.orm file looks like:

          Code:
          <?xml version="1.0"?>
          <!DOCTYPE orm SYSTEM "file:/javax/jdo/orm.dtd">
          <orm>
              <package name="org.datanucleus.samples.jdo.tutorial">
                  <class name="Inventory" table="Inventories">
                      <field name="name">
                          <column name="Name" length="100"/>
                      </field>
                      <field name="products"/>
                  </class>
          
                  <class name="Product" table="Products">
                      <inheritance strategy="complete-table"/>
                      <field name="id" value-strategy="increment">
                          <column name="Id"/>
                      </field>
                      <field name="name">
                          <column name="Name"/>
                      </field>
                      <field name="description">
                          <column name="Description"/>
                      </field>
                      <field name="price">
                          <column name="Price"/>
                      </field>
                  </class>
          
                  <class name="Book" table="Books">
                      <inheritance strategy="complete-table"/>
                      <field name="Product.id">
                          <column name="Id"/>
                      </field>
                      <field name="author">
                          <column name="Author"/>
                      </field>
                      <field name="isbn">
                          <column name="ISBN"/>
                      </field>
                      <field name="publisher">
                          <column name="Publisher"/>
                      </field>
                  </class>
              </package>
          </orm>
          Any help will be appreciated.
          Last edited by jbolat; Jul 10th, 2012, 11:19 AM. Reason: Correcting a mistake

          Comment


          • #6
            (I have already stated this before else where, but to be just, the fault was mine in that I did not realise that a new release of Datanucleus was released at the time. I have now updated my STS with the latest version of Datanucleus and it seems to work.

            Comment

            Working...
            X