当我尝试保存21,300个实体的列表时遇到问题,但是在数据库中仅保存了 [SELECT COUNT(id)=] 10,506 。
控制台输出显示准备保存的列表大小正确,因此代码“正确”。例如,如果我使用freq == 30使其仅循环一次,则此方法工作正常,因此当它循环多次时,似乎以某种方式链接到for循环。缺少的实体在人口中有些分散。
对为什么这种特殊行为有任何想法吗?
public void loadTickAll(int conid) {
System.out.println(">>>> MERGING <<<<<< Querying ticks for " + conid);
List<CandleTick> candlesHisto = histoCandleTickRepo.findByConidAll(conid, LocalDate.parse("2016-11-01"));
List<CandleTick> candlesLive = new ArrayList<>();
List<CandleTick> candles = Stream.of(candlesHisto, candlesLive).flatMap(Collection::stream)
.collect(Collectors.toList());
freqList.forEach((freq) -> {
if(freq>=30) {
System.out.println("Working on freq " + freq);
FlowMerger flowMerger = new FlowMerger(freq, contracts.get(conid));
List<CandleMerge> flow = flowMerger.createFlow(new ArrayList<>(candles));
Collections.reverse(flow);
System.out.println("Start saving " + freq + " - " + flow.size());
histoCandleMergeRepo.saveAll(flow);
System.out.println(freq + "/" + conid + " has been delivered and saved");
}
});
}
控制台输出
>>>> MERGING <<<<<< Querying ticks for 5
Working on freq 30
Start saving 30 - 21300
30/5 has been delivered and saved
application.properties
# jdbc.X
jdbc.driverClassName=org.postgresql.Driver
histo.jdbc.url=jdbc:postgresql://localhost:5432/trading2018
live.jdbc.url=jdbc:postgresql://localhost:5433/trading2018
jdbc.user=...
jdbc.pass=...
## hibernate.X
hibernate.default_schema=trading
hibernate.jdbc.lob.non_contextual_creation=true
hibernate.show_sql=false
hibernate.temp.use_jdbc_metadata_defaults=false
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.hbm2ddl.auto=validate
#hibernate.cache.use_second_level_cache=false
#hibernate.cache.use_query_cache=false
logging.level.org.springframework.web=ERROR
logging.level.com=DEBUG
logging.file=C:/tmp/application.log
答案 0 :(得分:1)
我设法找出问题所在。我显示了SQL,并注意到我正在更新而不是插入。
我的实体缺少一些注释...
@GeneratedValue(generator = "merge_id_seq")
@SequenceGenerator(name = "candleid_generator_generator", sequenceName = "merge_id_seq", initialValue = 1)
@Id
private int id;