private static net.sf.hibernate.NonUniqueObjectException adaptNonUniqueObjectException( final org.hibernate.NonUniqueObjectException ex) { final String message = ex.getMessage(); return new net.sf.hibernate.NonUniqueObjectException(ex.getMessage(), ex.getIdentifier(), null) { @Override public String getMessage() { return message; } @Override public String toString() { return toStringWithClassName(this, net.sf.hibernate.cache.CacheException.class); } }; }
public static int saveWithoutUpdate(List<FixedValue> fixedValues){ return HibernateUtil.withSession((session) -> { int saved = 0; session.beginTransaction(); for (FixedValue fixedValue : fixedValues){ try{ session.save(fixedValue); saved++; }catch(NonUniqueObjectException e){ log.warn("Could not save fixed value for subject {}, attribute {}: {}", fixedValue.getId().getSubject().getLabel(), fixedValue.getId().getAttribute().getLabel(), e.getMessage()); } if ( saved % 50 == 0 ) { session.flush(); session.clear(); } } session.getTransaction().commit(); return saved; }); } }
public static int saveWithoutUpdate(List<TimedValue> timedValues){ return HibernateUtil.withSession((session) -> { int saved = 0; session.beginTransaction(); for (TimedValue timedValue : timedValues){ try{ session.save(timedValue); saved++; }catch(NonUniqueObjectException e){ log.warn("Could not save timed value for subject {}, attribute {}, time {}: {}", timedValue.getId().getSubject().getLabel(), timedValue.getId().getAttribute().getDescription(), timedValue.getId().getTimestamp().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), e.getMessage()); } if ( saved % 50 == 0 ) { session.flush(); session.clear(); } } session.getTransaction().commit(); return saved; }); }
public static int save(List<FixedValue> fixedValues){ return HibernateUtil.withSession((session) -> { int saved = 0; session.beginTransaction(); for (FixedValue fixedValue : fixedValues){ try{ session.saveOrUpdate(fixedValue); saved++; }catch(NonUniqueObjectException e){ // This is happening because the TFL stations contain a duplicate ID log.warn("Could not save fixed value for subject {}, attribute {}: {}", fixedValue.getId().getSubject().getLabel(), fixedValue.getId().getAttribute().getLabel(), e.getMessage()); } if ( saved % 50 == 0 ) { // because batch size in the hibernate config is 50 session.flush(); session.clear(); } } session.getTransaction().commit(); return saved; }); }
public static int save(List<TimedValue> timedValues){ return HibernateUtil.withSession((session) -> { int saved = 0; session.beginTransaction(); for (TimedValue timedValue : timedValues){ try{ session.saveOrUpdate(timedValue); saved++; }catch(NonUniqueObjectException e){ // This is happening because the TFL stations contain a duplicate ID log.warn("Could not save timed value for subject {}, attribute {}, time {}: {}", timedValue.getId().getSubject().getLabel(), timedValue.getId().getAttribute().getDescription(), timedValue.getId().getTimestamp().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), e.getMessage()); } if ( saved % 50 == 0 ) { // because batch size in the hibernate config is 50 session.flush(); session.clear(); } } session.getTransaction().commit(); return saved; }); }