简体   繁体   中英

Hibernate Multiple Table Query Performance

I have a project which has a dashboard page. within that dashboard page, I have to show :

  1. Statistic Charts
  2. New information
  3. New user suggestions for the admin
  4. Number of new messages
  5. ETC

Now each of the above info are related to different tables within my database.

I have created different Entities and I'm using hibernate. Suppose client-A opens his dashboard, I should execute multiple queries for gathering all the info from all of those entities. Here are the challenges:

  1. Since each request runs in one thread at a time within my program, each queries must be finish for the other query to run (it's not simultaneously)
  2. We can not create multiple queries at once and map into different entities in hibernate
  3. The @Formula annotation can not map whole entity and just map single data type

I was thinking the best approach for having an efficient and fast output is to create one Big Native query and get all data at once with a Single query BUT if I'm gonna do this, I have to write native query and map everything by myself which makes the sole of using hibernate faint.

The other approach I'm thinking is to use executor service and multi-threading in my application

Now my question is, what is the best approach that I still can use hibernate mapping and issue high performance query ?

Thank you in advance

Your problem seems to stem from the notion that you believe you need to gather all the information for your dashboard in one controller call in order to render a single page. What you should do is take a step back and try to componentize your dashboard.

In other words, what I mean is take advantage of the asynchronous nature of Ajax.

There really is not a reason to use an executor service with today's modern browser tech when the browser can handle initiating multiple web requests asynchronously to render a single web page.

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