Я пытаюсь понять Hibernate.Я думал, что у меня все в порядке со всеми уроками интернета и со всеми, но я застрял с этим исключением.Я пытаюсь сохранить объект, который содержит пару списков в моей базе данных.Объект называется DataPointsListResultSet, и он содержит List предикатаDataPointsList и фактический DataPointsList
Вот модели:
(DataPointsListResultSet)
@Entity
public class DataPointsListResultSet {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer resultsetid;
@OneToMany(targetEntity= DataPoints.class,
mappedBy="dataPointsid",cascade = CascadeType.ALL,
fetch=FetchType.EAGER)
private List<DataPoints> predictDataPointsList = new ArrayList<>();
@OneToMany(targetEntity= DataPoints.class, mappedBy="dataPointsid",
cascade = CascadeType.ALL, fetch=FetchType.EAGER)
private List<DataPoints> actualDataPointsList = new ArrayList<>();
//getters and setters
(DataPoints)
@Entity
public class DataPoints {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer dataPointsid;
double x;
double y;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "resultsetid")
DataPointsListResultSet dataPointsListResultSet;
public DataPoints(){
}
//getters and setters
Вот некоторые из Stacktrace:
Message Request processing failed; nested exception is
org.springframework.dao.DataIntegrityViolationException: could not
execute statement; SQL [n/a]; constraint
[fk_337ty7afmhvcde8gwkd0sd6bq]; nested exception is
org.hibernate.exception.ConstraintViolationException: could not
execute statement
Description The server encountered an unexpected condition that
prevented it from fulfilling the request.
Exception
org.springframework.web.util.NestedServletException: Request
processing failed; nested exception is
org.springframework.dao.DataIntegrityViolationException: could not
execute statement; SQL [n/a]; constraint
[fk_337ty7afmhvcde8gwkd0sd6bq]; nested exception is
org.hibernate.exception.ConstraintViolationException: could not
execute statement
Root Cause
org.springframework.dao.DataIntegrityViolationException: could not
execute statement; SQL [n/a]; constraint
[fk_337ty7afmhvcde8gwkd0sd6bq]; nested exception is
org.hibernate.exception.ConstraintViolationException: could not
execute statement
, и это метод Java, который выполняет логику:
public DataPointsListResultSet predictPriceOneAhead (MultiLayerNetwork net, List<Pair<INDArray, INDArray>> testData, double max, double min, int exampleLength, String nomeDoConjunto, GeneralStockDataSetIterator iterator) {
double[] predicts = new double[testData.size()];
double[] actuals = new double[testData.size()];
DataPointsListResultSet resultSet = new DataPointsListResultSet();
List<DataPoints> predictDataPointsList = new ArrayList<>();
List<DataPoints> actualDataPointsList = new ArrayList<>();
resultSet.setPredictDataPointsList(predictDataPointsList);
resultSet.setActualDataPointsList(actualDataPointsList);
resultSetDao.save(resultSet);
for (int i = 0; i < testData.size(); i++) {
predicts[i] = net.rnnTimeStep(testData.get(i).getKey()).getDouble(exampleLength - 1) * (max - min) + min;
actuals[i] = testData.get(i).getValue().getDouble(0);
DataPoints predictDataPoint = new DataPoints();
predictDataPoint.setDataPointsListResultSet(resultSet);
predictDataPoint.setY(predicts[i]);
predictDataPoint.setX(i);
dataPointsDao.save(predictDataPoint);
predictDataPointsList.add(predictDataPoint);
DataPoints actuaDataPoint = new DataPoints();
actuaDataPoint.setDataPointsListResultSet(resultSet);
actuaDataPoint.setY(actuals[i]);
actuaDataPoint.setX(i);
dataPointsDao.save(actuaDataPoint);
actualDataPointsList.add(actuaDataPoint);
}
log.info("Print out Predictions and Actual Values...");
log.info("Predict,Actual");
for (int i = 0; i < predicts.length; i++) log.info(predicts[i] + "," + actuals[i]);
return resultSet;
}
Может ли кто-нибудь пролить свет на эту проблемуЯ был бы очень признателен!