JPA with mysql or mariadb

I am trying to setup JPA for mariadb using either mysql or mariadb driver. The JDBC persistance is working fine with mariadb, however I am looking into a way to save and restore a few OH variables…

I am using the same URL, User & Password as with the JDBC persistance. I tried mariadb and mysql as driver, but I am getting the error

Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver cannot be found by org.openhab.persistence.jpa_3.3.0

The file mysql-connector-java-8.0.22.jar is in the addons folder and I got the message

JDBC::openConnection: Driver is available::Yank setupDataSource

Any clue what is wrong?

Thanks,
Yves

I would suggest to set the JPA persistence binding into DEBUG logging mode.
In an other thread it was mentioned that the access rules on mysql server need to allow connections for openhab user.
Does the mysql server log show connection attempts ?

Neither DEBUG nor TRACE does show more information in the log during persistence.

The JDBC connection works using the mariadb driver. So I doubt that it is a mariadb server misconfiguration. However, I am not sure how to check connection attempts. At least the error log is empty…

I guess that somehow the driver cannot be found. That’s at least what the error suggests. I am clueless.

I don’t know if the driver is OSGI compliant. For non compliant drivers the manual page describes how to add these libraries to the classpath

Have you tried that ?

I tried using the drivers that come with “JDBC Persistence MariaDB” and “JDBC Persistence MySQL”, which are OSGI compliant. The “JDBC Persistence MariaDB” is working with the same URL/User/Password. Only the JPA Persistence is failing. I even tried copying the drivers to the add-on folder which doesn’t help.

Besides, I tried the one from https://mariadb.com/downloads/connectors/connectors-data-access/java8-connector/. I then see in the log (as for the other ones)

19:28:05.957 [INFO ] [.persistence.jdbc.internal.JdbcMapper] - JDBC::openConnection: Driver is available::Yank setupDataSource

so that one is OSGI compliant as well. But it doesn’t work either.

When I restart openHAB, then I get the following output from JPA:

19:53:00.847 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : BundleComponentActivator : ComponentHolder created.
19:53:00.870 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : ConfigurableComponentHolder configuration updated for pid org.openhab.jpa with change count 28
19:53:00.874 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : Dependency Manager created $000interface=org.openhab.core.items.ItemRegistry, filter=null, policy=static, cardinality=1..1, bind=null, unbind=null, updated=null, field=null, field-option=null, collection-type=null, parameter=0
19:53:00.885 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : Component created: DS=DS14, implementation=org.openhab.persistence.jpa.internal.JpaPersistenceService, immediate=false, default-enabled=true, factory=null, configuration-policy=require, activate=activate, deactivate=deactivate, modified=null configuration-pid=[org.openhab.jpa]
19:53:00.887 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : Component Services: scope=singleton, services=[org.openhab.core.persistence.PersistenceService, org.openhab.core.persistence.QueryablePersistenceService]
19:53:00.897 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : Component Properties: {}
19:53:00.898 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : Querying state disabled
19:53:00.909 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : Querying state disabled
19:53:00.910 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : Component can not be activated since it is in state disabled
19:53:00.921 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService] : Querying state disabled
19:53:00.923 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Updating target filters
19:53:00.931 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : No change in target property for dependency $000: currently registered: false
19:53:00.937 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] :  No existing service listener to unregister for dependency $000
19:53:00.943 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Setting target property for dependency $000 to null
19:53:00.946 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : New service tracker for $000, initial active: false, previous references: {}, classFilter: (objectClass=org.openhab.core.items.ItemRegistry), initialReferenceFilter (objectClass=org.openhab.core.items.ItemRegistry)
19:53:00.953 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : dm $000 tracker reset (closed)
19:53:00.957 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : dm $000 tracking 1 SingleStatic added {org.openhab.core.items.ItemRegistry}={service.id=182, service.bundleid=148, service.scope=bundle, component.name=org.openhab.core.internal.items.ItemRegistryImpl, component.id=27} (enter)
19:53:00.965 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : dm $000 tracking 1 SingleStatic active: false trackerOpened: false optional: false
19:53:00.972 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : dm $000 tracking 1 SingleStatic added {org.openhab.core.items.ItemRegistry}={service.id=182, service.bundleid=148, service.scope=bundle, component.name=org.openhab.core.internal.items.ItemRegistryImpl, component.id=27} (exit)
19:53:00.974 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : dm $000 tracker opened
19:53:00.978 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : registering service listener for dependency $000
19:53:00.985 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Changed state from disabled to unsatisfiedReference
19:53:00.987 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Component enabled
19:53:00.989 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : ActivateInternal
19:53:00.993 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Querying state unsatisfiedReference
19:53:01.003 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Querying state unsatisfiedReference
19:53:01.008 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Activating component from state unsatisfiedReference
19:53:01.017 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Querying state unsatisfiedReference
19:53:01.020 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Querying state unsatisfiedReference
19:53:01.022 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Changed state from unsatisfiedReference to satisfied
19:53:01.023 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : registration change queue [registered]
19:53:01.029 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Checking constructor public org.openhab.persistence.jpa.internal.JpaPersistenceService(org.openhab.core.items.ItemRegistry)
19:53:01.041 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : getReferenceClass: Looking for interface class org.openhab.core.items.ItemRegistry through loader of org.openhab.persistence.jpa.internal.JpaPersistenceService
19:53:01.044 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : getParameterClass: Found class org.openhab.core.items.ItemRegistry
19:53:01.046 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Found constructor with 1 arguments : public org.openhab.persistence.jpa.internal.JpaPersistenceService(org.openhab.core.items.ItemRegistry)
19:53:01.051 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : This thread collected dependencies
19:53:01.061 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : getService (single component manager) dependencies collected.
19:53:01.064 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Querying state satisfied
19:53:01.065 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Querying state satisfied
19:53:01.066 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : For dependency $000, optional: false; to bind: [[RefPair: ref: [{org.openhab.core.items.ItemRegistry}={service.id=182, service.bundleid=148, service.scope=bundle, component.name=org.openhab.core.internal.items.ItemRegistryImpl, component.id=27}] service: [null]]]
19:53:01.089 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : getting activate: activate
19:53:01.093 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Locating method activate in class org.openhab.persistence.jpa.internal.JpaPersistenceService
19:53:01.105 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Declared Method org.openhab.persistence.jpa.internal.JpaPersistenceService.activate([interface org.osgi.service.component.ComponentContext]) not found
19:53:01.107 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Found activate method: public void org.openhab.persistence.jpa.internal.JpaPersistenceService.activate(org.osgi.framework.BundleContext,java.util.Map)
19:53:01.109 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : invoking activate: activate: parameters [org.eclipse.osgi.internal.framework.BundleContextImpl, org.apache.felix.scr.impl.helper.ReadOnlyDictionary]
19:53:01.112 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : invoked activate: activate
19:53:01.121 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Set implementation object for component
19:53:01.123 [DEBUG] [ce.jpa.internal.JpaPersistenceService] - bundle org.openhab.persistence.jpa:3.3.0 (287)[org.openhab.persistence.jpa.internal.JpaPersistenceService(343)] : Changed state from satisfied to active

The exact error message when trying to persist an item using JPA is:

20:00:19.297 [WARN ] [org.openhab.core.items.GenericItem   ] - failed notifying listener 'org.openhab.core.persistence.internal.PersistenceManagerImpl@23d536da' about state update of item settingsHoliday: There were errors initializing your configuration: <openjpa-2.4.0-r422266:1674604 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "org.mariadb.jdbc.Driver" and URL "jdbc:mariadb://10.0.0.6/openhab".  You may have specified an invalid URL.
	at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:254)
	at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:122)
	at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:849)
	at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:732)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:310)
	at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1670)
	at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:650)
	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:202)
	at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:154)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
	at org.openhab.persistence.jpa.internal.JpaPersistenceService.store(JpaPersistenceService.java:145)
	at org.openhab.core.persistence.internal.PersistenceManagerImpl.handleStateEvent(PersistenceManagerImpl.java:152)
	at org.openhab.core.persistence.internal.PersistenceManagerImpl.stateChanged(PersistenceManagerImpl.java:473)
	at org.openhab.core.items.GenericItem.lambda$1(GenericItem.java:259)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver cannot be found by org.openhab.persistence.jpa_3.3.0
	at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:529)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:524)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168)
	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.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:84)
	... 21 more

org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-2.4.0-r422266:1674604 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "org.mariadb.jdbc.Driver" and URL "jdbc:mariadb://10.0.0.6/openhab".  You may have specified an invalid URL.
	at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:254)
	at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:122)
	at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:849)
	at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:732)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:310)
	at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1670)
	at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:650)
	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:202)
	at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:154)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
	at org.openhab.persistence.jpa.internal.JpaPersistenceService.store(JpaPersistenceService.java:145)
	at org.openhab.core.persistence.internal.PersistenceManagerImpl.handleStateEvent(PersistenceManagerImpl.java:152)
	at org.openhab.core.persistence.internal.PersistenceManagerImpl.stateChanged(PersistenceManagerImpl.java:473)
	at org.openhab.core.items.GenericItem.lambda$1(GenericItem.java:259)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver cannot be found by org.openhab.persistence.jpa_3.3.0
	at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:529)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:524)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168)
	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.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:84)
	... 21 more

	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:217) ~[?:?]
	at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:154) ~[?:?]
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226) ~[?:?]
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153) ~[?:?]
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59) ~[?:?]
	at org.openhab.persistence.jpa.internal.JpaPersistenceService.store(JpaPersistenceService.java:145) ~[?:?]
	at org.openhab.core.persistence.internal.PersistenceManagerImpl.handleStateEvent(PersistenceManagerImpl.java:152) ~[?:?]
	at org.openhab.core.persistence.internal.PersistenceManagerImpl.stateChanged(PersistenceManagerImpl.java:473) ~[?:?]
	at org.openhab.core.items.GenericItem.lambda$1(GenericItem.java:259) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.lang.RuntimeException: There were errors initializing your configuration: <openjpa-2.4.0-r422266:1674604 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "org.mariadb.jdbc.Driver" and URL "jdbc:mariadb://10.0.0.6/openhab".  You may have specified an invalid URL.
	at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:254)
	at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:122)
	at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:849)
	at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:732)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:310)
	at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1670)
	at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:650)
	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:202)
	at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:154)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
	at org.openhab.persistence.jpa.internal.JpaPersistenceService.store(JpaPersistenceService.java:145)
	at org.openhab.core.persistence.internal.PersistenceManagerImpl.handleStateEvent(PersistenceManagerImpl.java:152)
	at org.openhab.core.persistence.internal.PersistenceManagerImpl.stateChanged(PersistenceManagerImpl.java:473)
	at org.openhab.core.items.GenericItem.lambda$1(GenericItem.java:259)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver cannot be found by org.openhab.persistence.jpa_3.3.0
	at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:529)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:524)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168)
	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.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:84)
	... 21 more

	at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:324) ~[?:?]
	at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1670) ~[?:?]
	at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:650) ~[?:?]
	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:202) ~[?:?]
	... 11 more

Thanks for your assistance @Wolfgang_S, but I still have no clue what’s wrong. Any further suggestions?

  • what is the content of your jpa.cfg file ?
  • it looks like you do not use a port number in your connection string ( try to add it to see if that makes any difference )?
  • is 10.0.0.6 a separate host or is it the host OH runs on as well ? If it is an external host you can run a network sniffer to check if there are connection trials. But it looks like the error already occurs before connections are done.

The contents of the jpa.cfg file:

# connection string url
#url=jdbc:postgresql://<host>:5432/<databasename>
#url=jdbc:derby://<host>:1527/<databasename>;create=true
url=jdbc:mariadb://10.0.0.6/openhab

# driver class name
#driver=org.postgresql.Driver
#driver=org.apache.derby.jdbc.ClientDriver
driver=org.mariadb.jdbc.Driver

# username
user=<user>

# password
password=<password>

I tried with port number before. Doesn’t change anything. The problem seems to be the driver not the URL.

The database server is a separate host. It can be reached by the JDBC driver though. I will try to use a network sniffer tomorrow, but I guess the error occurs beforehand.

Please add the port again. For other connection strings the port is being used in examples as well. Could be that a default port is being used in case none is listed but by adding it you are on the save side.
Then reboot.

First part seems to hint on the connection string; second part of the error message as you wrote the driver.

I would use the driver that shows to work with JDBC persistence MariaDB configuration.
As stated above try to add the port again although the fallback should be the default port.

There is an other very old thread: JPA persistence with mysql or mariadb failing

For the moment I am out of ideas. May be I have more later.

Adding the port number (3306) and rebooting doesn’t change anything unfortunately.

The “caused by” in the error string suggests that the main error is the driver which is not found.

Regarding the old thread, I found that one too, that’s why I tried the MySQL driver in the first place. I also tried to add the tables, neither seems to help. I am still thinking that JPA can’t find the driver, but I have no clue how to debug this.

ok.

You can get the source code of the JPA binding and check for all the TRACE/DEBUG output you get.
I tried to find the location where the connection to the DB is established but was not able to locate it - I am not an expert in Java - so I might have missed something …
You may have a look at https://www.baeldung.com/jvm-list-all-classes-loaded . That page describes how to check for loaded classes. As far as I understand doing that one should be able to detect if the driver is loaded.

I have basic Java programming skills but not enough to debug this… any clue who is the maintainer for this bundle?

Maybe I should post an issue on GitHub?

Yes, try that option.

An issue has been submitted: [jpa] MariaDB and MySQL drivers not found · Issue #13375 · openhab/openhab-addons · GitHub

1 Like

1 week. no reaction… :frowning: