UpdateHandler gives exception "null into a non-nullable"

User a200fcbc5e

07-04-2011 10:49:41

Hi,

I'm looking to upgrade from JChem v5.4.1.1 from v5.2.6

I'm using the chemaxon.jchem.db.UpdateHandler class. With the code below using v 5.4.1.1, I get the following error.
Am I missing something out from the API or something else I'm doing wrong?
I don't get any errors when I use v5.2.6

Barry

Exception in thread "main" java.sql.SQLException: Attempt to insert null into a non-nullable column: column: CD_PRE_CALCULATED table: ONTOLOGY_TABLE in statement [INSERT INTO ONTOLOGY_TABLE (
CD_STRUCTURE,
CD_SMILES,
CD_FORMULA,
CD_SORTABLE_FORMULA,
CD_MOLWEIGHT,
CD_HASH,
CD_FLAGS,
CD_PRE_CALCULATED,
CD_TIMESTAMP,
CD_FP1,
CD_FP2,
CD_FP3,
CD_FP4,
CD_FP5,
CD_FP6,
CD_FP7,
CD_FP8,
CD_FP9,
CD_FP10,
CD_FP11,
CD_FP12,
CD_FP13,
CD_FP14,
CD_FP15,
CD_FP16) VALUES (?,?,?,?,?,?,?,?,NOW(),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]
   at org.hsqldb.jdbc.Util.throwError(Unknown Source)
   at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
   at chemaxon.jchem.db.UpdateHandler.execute(UpdateHandler.java:2347)
   at chemaxon.jchem.db.UpdateHandler.execute(UpdateHandler.java:2240)
   at toyJChem.JChemDemo.main(JChemDemo.java:31)

======================

package toyJChem;

import java.sql.Connection;
import java.sql.SQLException;

import chemaxon.formats.recognizer.SMILESRecognizer;
import chemaxon.jchem.db.DatabaseProperties;
import chemaxon.jchem.db.StructureTableOptions;
import chemaxon.jchem.db.TableTypeConstants;
import chemaxon.jchem.db.UpdateHandler;
import chemaxon.util.ConnectionHandler;

public class JChemDemo
{
   public static final String TABLE_NAME = "ONTOLOGY_TABLE";
   public static final String NODE_ID_COLUMN_NAME = "node_id";
   public static final String ORIGINAL_SMILES_COLUMN_NAME = "original_smiles";
      private static Connection connection;
   private static ConnectionHandler conn_handler;
      public static void main (String[] args) throws Exception
   {
       init();
       createTables();
              UpdateHandler handler = new UpdateHandler(conn_handler, UpdateHandler.INSERT, JChemDemo.TABLE_NAME , null);
       if ( SMILESRecognizer.canBeSMILES( "CC(=O)NCCC=O" ))
       {
           handler.setStructure( "CC(=O)NCCC=O" );
           handler.execute();
       }
   }
      private static void init() throws Exception
   {
       connection = ConnectionFactory.getConnection();
       conn_handler = new ConnectionHandler();
       conn_handler.setConnection( connection  );
   }
      private static void createTables() throws SQLException
   {
       DatabaseProperties.createPropertyTable(conn_handler);
       createTable();
   }
      private static void createTable() throws SQLException
   {
       StructureTableOptions tableOptions = new StructureTableOptions();
       tableOptions.name = JChemDemo.TABLE_NAME;
       tableOptions.tableType = TableTypeConstants.TABLE_TYPE_ANY_STRUCTURES;
              // Setting finger print parameters according to table type
       tableOptions.fp_numberOfInts = TableTypeConstants.FP_DEFAULT_LENGTH_IN_INTS[tableOptions.tableType];
       tableOptions.fp_numberOfOnes = TableTypeConstants.FP_DEFAULT_BITS_PER_PATTERN[tableOptions.tableType];
       tableOptions.fp_numberOfEdges = TableTypeConstants.FP_DEFAULT_PATTERN_LENGTH[tableOptions.tableType];
       UpdateHandler.createStructureTable(conn_handler, tableOptions);
   }
}



ChemAxon e274e1bada

08-04-2011 08:50:49

Hi,


we are trying to reproduce the issue with hsqldb, and respond soon.


Regards, Edvard

ChemAxon ebbce65bcf

12-04-2011 08:25:07

Hi Barry,


After some investigation it turned out that JChem cannot determine the type of the cd_pre_calculated field well under HSQLDB.It is added as a NULL type which is wrong, that's why you get the error message during the import. Version 5.5 will contain the bugfix for this.


For you, as you have already added this column, I think the easiest way would be to alter it:


ALTER TABLE <tablename> ALTER COLUMN cd_pre_calculated TINYINT DEFAULT 0 NOT NULL

I hope this helps.


Regards,


Roland


	
	

User a200fcbc5e

12-04-2011 13:25:10

Hi Roland,


Thanks for the reply and the workaround.


I get a similar error doing a search using JChemSearcher - using the same code as before, but with a different main() - shown below:


Fortunately, using a similar workaround as before (just different table and column) fixes the problem.


The workaround was:


ALTER TABLE JCHEMPROPERTIES_CR ALTER COLUMN IS_PROTECTED TINYINT DEFAULT 0 NOT NULL

This look like another bug that might need to be fixed.


Barry


===========


The error is :


Exception in thread "main" java.sql.SQLException: Attempt to insert null into a non-nullable column: column: IS_PROTECTED table: JCHEMPROPERTIES_CR
    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 chemaxon.jchem.db.CacheRegistrationUtil.registerCache(CacheRegistrationUtil.java:85)
    at chemaxon.jchem.db.StructureCache.tryRegistration(StructureCache.java:1427)
    at chemaxon.jchem.db.StructureCache.manageRegistration(StructureCache.java:1393)
    at chemaxon.jchem.db.StructureCache.loadIfNeeded(StructureCache.java:876)
    at chemaxon.jchem.db.JChemSearch.loadCacheIfNeeded(JChemSearch.java:2298)
    at chemaxon.jchem.db.JChemSearch.search1(JChemSearch.java:2015)
    at chemaxon.jchem.db.JChemSearch.search(JChemSearch.java:1853)
    at chemaxon.jchem.db.JChemSearch.setRunning(JChemSearch.java:1706)
    at chemaxon.jchem.db.JChemSearch.run(JChemSearch.java:1729)
    at toyJChem.JChemDemo.main(JChemDemo.java:40)


===


The new main() code:


        init();
        createTables();
        
        if ( SMILESRecognizer.canBeSMILES( "CC(=O)NCCC=O" ) )
        {
            JChemSearch searcher = new JChemSearch();
            searcher.setQueryStructure( "CC(=O)NCCC=O" );
            searcher.setConnectionHandler(conn_handler);
            searcher.setStructureTable( JChemDemo.TABLE_NAME );
            JChemSearchOptions searchOptions = new JChemSearchOptions();
            searchOptions.setMaxResultCount( 500 );
            searchOptions.setSearchType( SearchConstants.SUBSTRUCTURE );
            searcher.setSearchOptions(searchOptions);
            searcher.run();
        }

User c1ce6b3d19

14-04-2011 13:00:46

Hi Barry,


Thanks for the information.  My colleagues will look into this bug and reply shortly.


 


Jonathan Lee

ChemAxon a9ded07333

15-04-2011 15:41:44

Hi Barry,


Our next minor release (5.5.1) will contain the fix for the JCHEMPROPERTIES_CR related issue.


Thanks for your report!
Best regards,


Tamás



JCHEMPROPERTIES_CR