Skip to content

Commit

Permalink
[Re-import] fixed SQL exception when maxPace == NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgang-ch committed Oct 30, 2020
1 parent ee09ccf commit 921415c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bundles/net.tourbook/src/net/tourbook/data/TourData.java
Original file line number Diff line number Diff line change
Expand Up @@ -9221,6 +9221,10 @@ public boolean replaceAltitudeWithSRTM() {
return true;
}

public void resetMaxPace() {
maxPace = 0;
}

/**
* Reset sorted markers that they are sorted again.
*/
Expand Down
17 changes: 14 additions & 3 deletions bundles/net.tourbook/src/net/tourbook/database/TourDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@ public static <T> T saveEntity(final T entity, final long id, final Class<T> ent
public static TourData saveTour(final TourData tourData, final boolean isUpdateModifiedDate) {

/*
* prevent saving a tour which was deleted before
* Prevent saving a tour which was deleted before
*/
if (tourData.isTourDeleted) {
return null;
Expand All @@ -2246,7 +2246,7 @@ public static TourData saveTour(final TourData tourData, final boolean isUpdateM
}

/*
* prevent saving a tour when a person is not set, this check is for internal use that all
* Prevent saving a tour when a person is not set, this check is for internal use that all
* data are valid
*/
if (tourData.getTourPerson() == null) {
Expand All @@ -2255,12 +2255,23 @@ public static TourData saveTour(final TourData tourData, final boolean isUpdateM
}

/*
* check size of varcar fields
* Check size of varcar fields
*/
if (tourData.isValidForSave() == false) {
return null;
}

/*
* Check invalid data
*/
if (Float.isNaN(tourData.getMaxPace())) {

// this occurred and caused an exception:
// Caused by: java.sql.SQLDataException: The resulting value is outside the range for the data type DOUBLE.

tourData.resetMaxPace();
}

/*
* Removed cached data
*/
Expand Down

5 comments on commit 921415c

@wolfgang-ch
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FJBDev Can you check why maxPace can be NaN which causes an SQL exception when saving a tour, this occured when I reimported a tour.

mt-max-pace-nan

!MESSAGE Tour cannot be saved in the database
!STACK 0
org.hibernate.exception.DataException: could not update: [net.tourbook.data.TourData#20129261355579]
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2443)
	at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2325)
	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2625)
	at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
	at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
	at net.tourbook.database.TourDatabase.saveTour(TourDatabase.java:2324)
	at net.tourbook.tour.TourManager.saveModifiedTours_OneTour(TourManager.java:2613)
	at net.tourbook.tour.TourManager.saveModifiedTours(TourManager.java:2491)
	at net.tourbook.tour.TourManager.saveModifiedTour(TourManager.java:2434)
	at net.tourbook.importdata.RawDataManager.actionReimportTour_30(RawDataManager.java:1108)
	at net.tourbook.importdata.RawDataManager.reimportTour(RawDataManager.java:2030)
	at net.tourbook.importdata.RawDataManager$1.run(RawDataManager.java:661)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
Caused by: java.sql.SQLDataException: The resulting value is outside the range for the data type DOUBLE.
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedPreparedStatement.setFloat(Unknown Source)
	at org.hibernate.type.FloatType.set(FloatType.java:60)
	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:131)
	at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2015)
	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2389)
	... 20 more
Caused by: ERROR 22003: The resulting value is outside the range for the data type DOUBLE.
	at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
	at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
	at org.apache.derby.iapi.types.NumberDataType.normalizeDOUBLE(Unknown Source)
	at org.apache.derby.iapi.types.SQLDouble.setValue(Unknown Source)
	... 26 more

@FJBDev
Copy link
Collaborator

@FJBDev FJBDev commented on 921415c Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that issue occur when you reimport any tour ? or only specific tour ?

I will try to reproduce and investigate

@wolfgang-ch
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was only this specific tour but I found other tours where maxPace is OK. I need to debug hibernate to find the troublesome field, it is not so easy to detect.

@FJBDev
Copy link
Collaborator

@FJBDev FJBDev commented on 921415c Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, all my tours have a valid maxPace so there is something in your specific tour that create a NaN value.
You can send it to me if you want me to investigate.

I am surprised because the computation of MaxPace is simple in my commit

@wolfgang-ch
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug occur when the none smoothing algorithm is used and timeDiff == 0, fixed in 60ec227

mt-timediff-0

Please sign in to comment.