OpenHab2, JPA Binding, MySQL DB

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 Removed PersistentStateRestorer by teichsta · Pull Request #3125 · openhab/openhab1-addons · GitHub). 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.

It is finally running.
I have imported the MySQL Binding and deleted all References to PersistentStateRestorer.
After that i still had the problem that config parameter is still null.

Dictionary<String, ?> config
I think im doing something wrong by configure the binding, but i really dont know what.
For testing purpose i coded the value direct into the code and skiped that part of the code.

With this it works , even the restore seems to work.

2015-09-07 10:01:13 [DEBUG] [.p.m.i.MysqlPersistenceService:559  ] - mySQL query: item is Weather_Temperature
2015-09-07 10:01:13 [DEBUG] [.p.m.i.MysqlPersistenceService:619  ] - mySQL: query:SELECT Time, Value FROM Item1 ORDER BY Time DESC LIMIT 0,1
2015-09-07 10:01:13 [DEBUG] [.p.m.i.MysqlPersistenceService:659  ] - mySQL: query returned 1 rows in 47ms
2015-09-07 10:01:13 [DEBUG] [o.e.s.m.p.i.PersistenceManager:380  ] - Restored item state from '06.09.2015 20:03:35' for item 'Weather_Temperature' -> '14'

My weather item is properly stroed into my database.
Database Tables

Next i will try to solve the “config is null” problem.