This is actually not a question but maybe it's a bug.
I have an array of objects and I perform a loop in order to save it into the database:
for (ThresholdParams p : threshold.getThresholdParams()) {
if (!p.getInitialValue().isNaN() && !p.getStepValue().isNaN()) {
thresholdParamsRepository.save(p);
}
}
thresholdParamsRepository is an interface extending CrudRepository.
When the array do not have any invalid NaN value it works fine. If I perform a debug it stops everytime in the save sentence.
But if the 8th(for example) element of the array has a NaN value it performs all the for loop without performing the if and crashes because a mysql exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'NaN' in 'field list'
I used a break point to debug it in the save sentence but it skiped it after the first save. I debuged all and it perform all the saves until de 8th when it crashed. It did not commited the changes into the database.
I have solved it removing the elements with nan values but I do not know if it is a bug related to java or to spring data jpa.
This is the ThresholdParams class:
@Entity
@Table(name="threshold_params")
public class ThresholdParams {
@EmbeddedId
private ThresholdParamsId thresholdParamsId;
@Column(name="step_value")
private Float stepValue;
@Column(name="initial_value", nullable= true)
private Float initialValue;
@ManyToOne
@JoinColumn(name="contextSourceId",insertable=false, updatable= false)
private ContextSource contextSource;
@Column(name="is_enabled", columnDefinition="bit default 1")
private boolean isEnabled;
public boolean getIsEnabled() {
return isEnabled;
}
public void setIsEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}
@ManyToOne
@JoinColumn(name="thresholdId",insertable=false, updatable= false)
private Threshold threshold;
}