H2 function alias - ClassNotFoundException

193 views
Skip to first unread message

Васил Зорев

unread,
Jul 18, 2021, 2:58:16 PM7/18/21
to H2 Database
Hello,

I have some issues with a function. I'm almost sure it is a "user error" somewhere in my setup, however cannot determine it yet. Will try to explain.

I have an integration tests which boots up an Apache Karaf and executes commands on it via SSH. This Karaf is connected to an H2 database (let's say - "karafdb"). From within the test itself I am trying to create a new H2 function in the karafdb. To do this, I currently get a java.sql.Connection via JDBC, using the AUTO_SERVER=true connection property. Then execute the following statements:

DROP ALIAS IF EXISTS DBFill;
CREATE ALIAS DBFill FOR "cspu.it.H2Procedures.dbFill";

(cspu is an abbreviated package name).

Then I get the following error:

org.h2.jdbc.JdbcSQLSyntaxErrorException: 
Class "com.seeburger.portal.ums.it.H2Procedures" not found; SQL statement:
DROP ALIAS IF EXISTS DBFill; [90086-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:576)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
at org.h2.message.DbException.get(DbException.java:194)
at org.h2.util.JdbcUtils.loadUserClass(JdbcUtils.java:199)
at org.h2.engine.FunctionAlias.loadClass(FunctionAlias.java:138)
at org.h2.engine.FunctionAlias.load(FunctionAlias.java:114)
at org.h2.engine.FunctionAlias.init(FunctionAlias.java:99)
at org.h2.engine.FunctionAlias.newInstance(FunctionAlias.java:73)
at org.h2.command.ddl.CreateFunctionAlias.update(CreateFunctionAlias.java:48)
at org.h2.command.CommandList.executeRemaining(CommandList.java:50)
at org.h2.command.CommandList.update(CommandList.java:67)
at org.h2.command.Command.executeUpdate(Command.java:251)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:406)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:183)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: cspu.it.H2Procedures not found by com.h2database [48]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1565)
at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:78)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1950)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at org.h2.util.JdbcUtils.loadUserClass(JdbcUtils.java:192)
... 11 more

at org.h2.message.DbException.getJdbcSQLException(DbException.java:576)
at org.h2.engine.SessionRemote.done(SessionRemote.java:611)
at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:237)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:228)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201)
at cspu.it.UMSSyncBulkRoundtripIT.createDBFillProcedure(UMSSyncBulkRoundtripIT.java:332)
...
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:451)

The class H2Procedures, which H2 cannot find is in the same package as the test class (UMSSyncBulkRoundtripIT), only H2Procedures is in the maven source folder (not the test folder).
If possible, I would prefer to get this running, so to create a function from an existing compiled class. This is because my Java source function is pretty large and contains class fields and several private methods.

I saw another possibility is to define the function directly as source code. If that would be the "solution", are such fields and additional private methods supported in such as source code approach syntax? If yes, how ?

Sorry for the long text, any help would be appreciated!
Regards,
Vassil


Васил Зорев

unread,
Jul 18, 2021, 3:32:27 PM7/18/21
to H2 Database
I get the following error (even with AUTO_SERVER=true):

org.h2.message.DbException: Database may be already in use: null. Possible solutions: close all other connection(s); use the server mode [90020-200]
Reply all
Reply to author
Forward
0 new messages