Creates a new ConnectionHandler from Hibernate Session

User 38c1febedf

28-11-2012 07:08:53

Hi All.


When i create a new ConnectionHandler from Hibernate Session, i use these code blow:


public class JChemBaseDao extends HibernateDaoSupport{

public int[] query(String mol,int searchType,float similary){

int[] hitID = null;

java.sql.Connection conn = this.getSession().connection();

ConnectionHandler connHandle = new ConnectionHandler(conn,JCHEM_PROPERTY_TABLE);


JChemSearch jcs = new JChemSearch();

JChemSearchOptions jcSearchOptions = new JChemSearchOptions(searchType);

jcSearchOptions.setDissimilarityThreshold(similary);

int hitSum = 0;

try {

jcs.setStructureTable(JCHEM_STRUCTURE_TABLE);

jcs.setQueryStructure(mol);

jcs.setSearchOptions(jcSearchOptions);

jcs.setResultTable(JCHEM_RESULT_TABLE);

jcs.setOrder(JChemSearch.ORDERING_BY_ID_OR_SIMILARITY);

jcs.setRunMode(JChemSearch.RUN_MODE_SYNCH_COMPLETE);

System.out.println("\n********* start running *********\n");

jcs.setConnectionHandler(connHandle);

jcs.run();

System.out.println("\n********* end running *********\n");

hitSum = jcs.getResultCount();

if (hitSum > 0) {

hitID = jcs.getResults();
}

} catch (Exception e) {

e.printStackTrace();

System.out.print("error in connection the database!");
}
}
}

but i got these errors


 


java.sql.SQLException: The url cannot be null

at java.sql.DriverManager.getConnection(DriverManager.java:554)

at java.sql.DriverManager.getConnection(DriverManager.java:185)

at chemaxon.jchem.db.CacheRegistrationUtil.registerCache(CacheRegistrationUtil.java:101)

at chemaxon.jchem.db.CachePool.tryRegistration(CachePool.java:726)

at chemaxon.jchem.db.CachePool.manageRegistration(CachePool.java:461)

at chemaxon.jchem.db.JChemCache.loadCache(JChemCache.java:369)

at chemaxon.jchem.db.JChemSearch.loadCache(JChemSearch.java:2792)

at chemaxon.jchem.db.JChemSearch.search1(JChemSearch.java:2449)

at chemaxon.jchem.db.JChemSearch.search(JChemSearch.java:2280)

at chemaxon.jchem.db.JChemSearch.setRunning(JChemSearch.java:2000)

at chemaxon.jchem.db.JChemSearch.run(JChemSearch.java:2023)

at com.scienview.common.dao.JChemBaseDao$1.execute(JChemBaseDao.java:48)

at org.hibernate.impl.SessionImpl.doWork(SessionImpl.java:1997)

 


And the JChem version is V5.10.0


 


Can someone help me?thanks

ChemAxon abe887c64e

28-11-2012 11:02:10

Hi,


Thank you for your enquiery. We will get back to you soon.


Krisztina

ChemAxon 9991eff751

29-11-2012 11:05:58

hello,


i will describe the jchem end of the problem:


the jchem instance is trying to make it's cache registration into the database - this involves an insert


- because the passed connection is not commitable, it tries to create a new commitable connection


- but the connection passed doesn't have those properties which fires the exception


you can try to workaround this problem by passing a commitable ConnectionHandler like:


            Properties props = getConnectionProperties();
            ConnectionHandler ch = new ConnectionHandler();
            if (!ch.loadValuesFromProperties(props)) {
                throw new IOException("Insufficient connection data.");
            }
            ch.connectToDatabase();


is this workaround helped you?

ChemAxon 9c0afc9aaf

30-11-2012 17:18:08

Hi,


Please see the "Structure cache identification and registration" section here:


http://www.chemaxon.com/jchem/doc/dev/java/intro/index.html#connect


Basically you should not be inside a transation (Connection.getAutoCommit() should be true) when a temporary cache registration happens.


(The commit is required to ensure proper auditing and cache integrity)


If it has not been taken care of yet, we try to do this at the first search.


You can either have a permanent cache registration (e.g. single instance server process) and set the ID for that, or register a temporary one explicitely before you enter a transaction.


You should do this once per JVM instance, e.g. when your application starts up / connects to the DB, and then we won't have to try to register inside the transaction.


Please let us know if you have further questions on this.


Best regards,


Szilard