简体   繁体   中英

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.

Since the entity has another entity as a child which is always needed Fetch=ALL is used.

When running the query using Hibernate it takes around 3-4 minutes (It's a small table with around 600 records). When running a native SQL query it takes 0.17 sec. 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)

see The @Fetch annotation mapping for explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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