OpenHab2, JPA Binding, MySQL DB

Hi,

iam trying to store the yahoo weather data into a MySQL Database using OpenHab1 JPA Binding.
At first i imported the JPA Binding into OpenHab2.
By stratring the Binding i get the error message “Got a null properties object!

My JPA persistance File
Name: jpa.persist

Strategies {
    everyHour : "0 0 * * * ?"
    everyDay  : "0 0 0 * * ?"
    default = everyChange
}

Items {
    * : strategy = everyChange, everyDay, restoreOnStartup
    Temperature*, Weather* : strategy = everyChange
}

My JPA config File
Name: jpa.cfg

# connection string url
jpa:url=jdbc:mysql://localhost:3306/openhab2

# driver class name
jpa:driver=com.mysql.jdbc.Driver

# username
user=admin

# password
password=XXX

It seems that the JPA Binding can’t find the jpa.cfg file.
The documentation of the Binding says that the JPA config has to be stored into openhab.conf for OH1.
In OH2 i stored it simply into the jpa.cfg file.

Do i have to change something else, so the Binding is using the jpa.cfg file and is not searching for openhab.conf ?

best regards Philip

Under OH2, you should have the jpa.cfg in the services folder (which you probably have), but the problem is likely that you need to remove the jpa from the from of the config lines -:

# connection string url
url=jdbc:mysql://localhost:3306/openhab2

Which version of OH2 are you using? The released alpha builds or the snaphots on cloudbees?

There was a problem with the MySQL binding (Issue #312) which is resolved in the meantime, but the solution came after the Alpha 2.

Just to note that he’s not using the mySQL service - the JPA service is being used and I’m not sure if the same problem existed there. It might have as the issue was related to an extension that was added to a number of persistence services in OH1 that had to be removed…

Sorry, I misread the configuration, reading only the “mysql” in the topic and JDBC urls :blush:

# connection string url
url=jdbc:mysql://localhost:3306/openhab2

I already tried this with the same result.

I think the problem is at this point in the code.

JPA Binding
Class: JpaConfiguration

public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
		logger.debug("Update config...");
		
		if(properties == null) {
			logger.error("Got a null properties object!" );
			return;
		}

This methods has a parameter called proberties witch contains the JPA configuration settings. In my case it is null. I assume that the jpa.cfg is not read properly so the informations can’t be stored into the dictionary. I was looking for the point where this class is used, but i can’t find it.

I’m pretty sure it’s wrong though - it may not matter for some configs that have a good default, but the URL is probably required?

Regarding the error, I was recently told that this error isn’t anything to worry about -:

You don’t actually say if persistence is working or not. I’m assuming not, but please confirm because if it is working, then you should just ignore this error as it (apparently) doesn’t mean anything - the null dictionary case is (apparently!) normal.

I tried it out , but it does not work.

That is really nice to know, i focused my troubleshooting on this point.

I think,I will write a short Java-Programm to check if my MySQL Server is working properly.

The JPA Documentation says:

The binding will create one table “historic_item” where all item states are stored. The item state as such is stored as a string representation.

So i don’t have to create any table on my own right ?
I only create the database and the JPA-Binding is doing the rest.

That is probably correct, but to be honest, I don’t use the JPA binding - I’m using (or was using untill recently) the mysql binding… It works in the same way though in that you just need to create the database, and the tables are created automatically.

Correct. I am using the JPA binding, and all necessary tables (actually, there is only one in which all the items get persisted into) are created if they do not already exist.

Does the MYSQL Binding work with OpenHab2 ?
I saw it on the incompatible list.

Are you using Openhab1 or Openhab2 ?

Openhab2 with the daily builds from cloudbees. The “naked” MySQL binding did not work for me (because of the Issue 312 I mentioned a few posts ago), so I started using the JPA binding.

I’m personally using OH2. mySQL works with OH2 - there was a problem with some versions of most persistence services (not just mySQL) with OH2 due to something that was added to OH1, and this has now been removed.

So, I think that the current version of mySQL is now ok (although I’ve not tested it). Alternatively, a version before 1.6.1 I think is also ok (and I have tested that with OH2).

After importing the MySQL Bindung i get an error.

The import of org.openhab.core.persistence.PersistentStateRestorer can not be resolved.

Ok - that’s the problem that I thought was resolved… Looking at the issues below, it looks like it’s not merged yet…


If you use the mySQL in OH 1.6, this problem shouldn’t exist.

Chris

I cloned the Openhab2 Repo a while ago, maybe jam using a old version.
I will clone the actual version of openhab2 repo and test if the problem still exists.

Hi,

this issue IS resolved (see https://github.com/openhab/openhab/pull/3125). I didn’t close the issue since some users wanted to double check the solution though. So consider this issue resolved in the latest OH1 builds. I would assume the latest OH2 distribution will also contain the actual persistence service bundles.

Best, Thomas E.-E.

Thanks Thomas :smile:

thx, i will try it tomorrow.

ftr: since i am waiting for feedback the PR has not been merged into master yet. But please feel free to build it yourself and testing it.

Thanks, Thomas E.-E.