gpt4 book ai didi

java - Spring boot - Jpa - SaveAll(Entity ) 数据库中缺少实体

转载 作者:行者123 更新时间:2023-12-02 10:27:41 28 4
gpt4 key购买 nike

当我尝试保存包含 21,300 个实体的列表时遇到问题,但在数据库中仅保存 [SELECT COUNT(id) = ] 10,506

控制台输出表明准备保存的列表的大小是正确的,因此代码是“正确的”。例如,如果我让它仅以 freq==30 循环一次,则效果很好,因此当它循环多次时,它似乎以某种方式链接到 foreach 循环。失踪实体在人群中有些分散。

知道为什么会出现这种特殊行为吗?

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

应用程序属性

# 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

最佳答案

我设法追踪到这个问题。我展示了 SQL 并注意到我正在更新而不是插入。

我的实体缺少一些注释...

@GeneratedValue(generator = "merge_id_seq")
@SequenceGenerator(name = "candleid_generator_generator", sequenceName = "merge_id_seq", initialValue = 1)
@Id
private int id;

关于java - Spring boot - Jpa - SaveAll(Entity <S>) 数据库中缺少实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53809096/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com