简体   繁体   English

急于获取休眠状态需要很长时间

[英]Hibernate fetch eagerly takes very long time

I have an hibernate query that runs on server startup to sync data from Mysql to our cache server. 我有一个在服务器启动时运行的休眠查询,用于将数据从Mysql同步到我们的缓存服务器。

Since the entity has another entity as a child which is always needed Fetch=ALL is used. 由于该实体具有另一个始终作为子实体的实体,因此始终使用Fetch = ALL。

When running the query using Hibernate it takes around 3-4 minutes (It's a small table with around 600 records). 使用Hibernate运行查询时,大约需要3-4分钟(这是一个小表,大约有600条记录)。 When running a native SQL query it takes 0.17 sec. 运行本机SQL查询时,需要0.17秒。 What am I missing? 我想念什么?

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "hotLeadConfigId")
private Set<HotLeadSpecialPagesEntity> specialPages = new HashSet<HotLeadSpecialPagesEntity>();

Here is the query I am making: 这是我正在查询: 在MySQL Phpmyadmin上查询时间

Try to annotate it with @Fetch(FetchMode.JOIN) or @Fetch(FetchMode.SUBSELECT) 尝试使用@Fetch(FetchMode.JOIN)@Fetch(FetchMode.SUBSELECT)对其进行注释

see The @Fetch annotation mapping for explanation. 有关说明,请参见@Fetch注释映射

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM