Exception from PgServerThread.initDb

46 views
Skip to first unread message

Ronit

unread,
Jul 13, 2022, 9:56:05 AMJul 13
to H2 Database
Hello,
I am getting this exception after getting the Connection object.


DataSource dataSource = JdbcConnectionPool.create("ConnectionString", user,
                passwd);
Connection conn = dataSource.getConnection();

When I try to insert the data , I get this exception .

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NullPointerException
    at org.h2.server.pg.PgServerThread.initDb(PgServerThread.java:1147)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:566) 


Any suggestion or advise on this is appreciated 
Thanks 

Noel Grandin

unread,
Jul 13, 2022, 10:29:39 AMJul 13
to h2-da...@googlegroups.com
You are obviously doing something rather unusual because initDb is not supposed to be called via reflection.

So we're going to need a complete standalone test-case to be able to help.

Ronit

unread,
Jul 14, 2022, 4:06:38 AMJul 14
to H2 Database

What my real issue is , I am trying to migrate from H2 1.3.176 to H2 2.1.214 .  In my code we are using the Lucene Functionality of H2 as well as the H2 database.
What my question is :
    - What are the changes I might have to do ?
          e.g. MVStore, Connection String 
   - Will the database files dbName.h2.db , dbName.lock.db, dbName.mv.db and dbName.track.db work in the latest version or I will have to change those files and Queries as well?
   - How Session has changed ? SessionLocal and SessionRemote,
           I was lookinginto the code and I saw that the object of SessionLocal in the PgServerThread.initDb() is null. So I checked that too and found that in  PgServerThread.process()                          , session = Engine.createSession(ci)  is returning null. 

Evgenij Ryazanov

unread,
Jul 14, 2022, 4:49:09 AMJul 14
to H2 Database
Hello.


> Will the database files dbName.h2.db , dbName.lock.db, dbName.mv.db and dbName.track.db work in the latest version
No, you need to export your databases to SQL scripts with old version of H2 and create new databases with the new version and execute these scripts (this procedure was always required to upgrade between different versions):
https://h2database.com/html/tutorial.html#upgrade_backup_restore
You may need to add FROM_1X to import options, documentation suggests VARIABLE_BINARY, but FROM_1X can handle incorrect grammar used by old versions of H2 much better, unfortunately, documentation isn't up to date.

There is also a org.h2.tools.Upgrade utility in H2 2.*.*, you can try to use it instead (it requires access to Internet to download an old version).

You can also try a third-party upgrade tool:
https://github.com/manticore-projects/H2MigrationTool


> or I will have to change those files and Queries as well?
It depends on their correctness, new versions of H2 are more restrictive and many bugs were fixed, there is no bug-for-bug emulation for older versions.


> How Session has changed ?
It is not a part of API, applications should never try to use it directly. What exactly are you trying to do with it?


> I was lookinginto the code and I saw that the object of SessionLocal in the PgServerThread.initDb() is null.
PgServerThread should never be used by applications and librarires. If you need to start the PG server to allow connections from ODBC drivers for PostgreSQL, you should use
org.h2.tools.Server.createPgServer(optional_arguments).start();
or command-line options.
This server is also started automatically when you start H2 as a service without parameters:
java -jar h2-*.jar

> Engine.createSession(ci) is returning null
This method never returns null in H2 itself, it either returns an instance, or throws an exception. If you use modified sources, reflection, or some code injection and modification libraries everything in possible, but it that case it isn't a problem of H2.

Ronit

unread,
Jul 15, 2022, 2:52:48 AMJul 15
to H2 Database
Hello again,

My code was using H2 with MV_Store=false previously , what should I do to get the same behavior ?
Because now I am not able to find those tables from the database even after creating the connection.

Thanks 

Ronit

unread,
Jul 15, 2022, 3:37:21 AMJul 15
to H2 Database
Or rather , What are the changes that one should make if it is the case of migration to H2-2.1.214 from H2-1.3.176

Thanks.

Reply all
Reply to author
Forward
0 new messages