mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[jpa] Do not log failure to persist item with duplicate timestamp as error (#15978)
* [jpa] ignore EntityExistsException in case the user manually added a UNIQUE constraint to the database, openHAB might send duplicate timestamps. effectively this means the first attempt is kept, while others are dropped. as long as you're using sub-second timestamps, this shouldn't be an issue - the state updates truly should be duplicates Signed-off-by: Cody Cutrer <cody@cutrer.us> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
ba3c98438d
commit
4208400baf
@ -19,6 +19,7 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.EntityExistsException;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import javax.persistence.Persistence;
|
||||||
@ -164,7 +165,13 @@ public class JpaPersistenceService implements QueryablePersistenceService {
|
|||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
logger.debug("Persisting item...done");
|
logger.debug("Persisting item...done");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error while persisting item! Rolling back!", e);
|
if (e.getCause() instanceof EntityExistsException) {
|
||||||
|
// there's a UNIQUE constraint in the database, and we tried to write
|
||||||
|
// a duplicate timestamp. Just ignore
|
||||||
|
logger.debug("Failed to persist item {} because of duplicate timestamp", name);
|
||||||
|
} else {
|
||||||
|
logger.error("Error while persisting item! Rolling back!", e);
|
||||||
|
}
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
} finally {
|
} finally {
|
||||||
em.close();
|
em.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user