Hello,
I have been trying for the past hours to set-up the JPA persistence service with mysql (or mariadb) to no avail. The difficulty I face is that everything seems to be set-up correctly but the persistence then fails without any message.
Here is my debug log:
avril 11 23:10:14 jam start.sh[29978]: 2016-04-11 23:10:14.958 [DEBUG] [.o.p.j.i.JpaPersistenceService] - Activating jpa binding…
avril 11 23:10:14 jam start.sh[29978]: 2016-04-11 23:10:14.963 [DEBUG] [.o.p.j.i.JpaPersistenceService] - Activating jpa binding…done
avril 11 23:10:15 jam start.sh[29978]: 2016-04-11 23:10:15.018 [DEBUG] [.jpa.internal.JpaConfiguration] - Update config…
avril 11 23:10:15 jam start.sh[29978]: 2016-04-11 23:10:15.020 [DEBUG] [.jpa.internal.JpaConfiguration] - url: jdbc:mysql://jam:3306/openhab
avril 11 23:10:15 jam start.sh[29978]: 2016-04-11 23:10:15.022 [DEBUG] [.jpa.internal.JpaConfiguration] - driver: com.mysql.jdbc.Driver
avril 11 23:10:15 jam start.sh[29978]: 2016-04-11 23:10:15.024 [INFO ] [.jpa.internal.JpaConfiguration] - syncmappings was not specified!
avril 11 23:10:15 jam start.sh[29978]: 2016-04-11 23:10:15.026 [DEBUG] [.jpa.internal.JpaConfiguration] - Update config…done
So looks fine. Then when I trigger persistence through activation of an item:
avril 11 23:10:45 jam start.sh[29978]: 2016-04-11 23:10:45.827 [DEBUG] [.o.p.j.i.JpaPersistenceService] - Storing item: seContact_Office
avril 11 23:10:46 jam start.sh[29978]: 2016-04-11 23:10:46.002 [DEBUG] [.o.p.j.i.JpaPersistenceService] - Stored new value: OPEN
avril 11 23:10:46 jam start.sh[29978]: 2016-04-11 23:10:46.003 [DEBUG] [.o.p.j.i.JpaPersistenceService] - Creating EntityManagerFactory…
avril 11 23:10:47 jam start.sh[29978]: 2016-04-11 23:10:47.177 [DEBUG] [.o.p.j.i.JpaPersistenceService] - Creating EntityManagerFactory…done
and silent. Another further activation:
avril 11 23:10:52 jam start.sh[29978]: 2016-04-11 23:10:52.477 [DEBUG] [.o.p.j.i.JpaPersistenceService] - Storing item: seContact_Office
avril 11 23:10:52 jam start.sh[29978]: 2016-04-11 23:10:52.482 [DEBUG] [.o.p.j.i.JpaPersistenceService] - Stored new value: CLOSED
Looking at the code (JpaPersistenceService.java from line 109), something fails here:
JpaPersistentItem pItem = new JpaPersistentItem();
try {
String newValue = StateHelper.toString(item.getState());
pItem.setValue(newValue);
logger.debug("Stored new value: {}", newValue);
} catch (Exception e1) {
logger.error("Error on converting state value to string: {}", e1.getMessage());
return;
}
pItem.setName(name);
pItem.setRealName(item.getName());
pItem.setTimestamp(new Date());
EntityManager em = getEntityManagerFactory().createEntityManager();
try {
logger.debug("Persisting item...");
// In RESOURCE_LOCAL calls to EntityManager require a begin/commit
em.getTransaction().begin();
em.persist(pItem);
em.getTransaction().commit();
logger.debug("Persisting item...done");
} catch (Exception e) {
logger.error("Error on persisting item! Rolling back!");
logger.error(e.getMessage(), e);
em.getTransaction().rollback();
} finally {
em.close();
}
Indeed the logs show that OpenHab goes through “Stored new value: etc”, but never reaches the “try” after getEntityManagerFactory().createEntityManager();
I believe something fails around:
em.getTransaction().begin();
em.persist(pItem);
em.getTransaction().commit();
But I don’t know how to debug that part. Any help appreciated.
L.