1

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

8
  • 1
    You have put a good amount of effort in writing this post, but at the end, it's just asking for an opinion, which is not suitable for this site. Commented Jun 6, 2018 at 15:01
  • @BheshGurung this is not an opinion, I'm asking for best approach implementing a right and appropriate application. This is completely technical, you better read the question again Commented Jun 6, 2018 at 15:46
  • Sorry, but when you're saying, "what is the best approach", you are simply asking for an opinion. Commented Jun 6, 2018 at 15:48
  • @BheshGurung it's not that. if you say this so, there should not be any design pattern question within this site. they are also best approaches in software development Commented Jun 6, 2018 at 15:51
  • There can be design pattern related questions. e.g. you can ask, "How to implement Singleton pattern in Java?". Then five different people will show you five different ways to implement it. Which is ok. But you can also ask, "Which implementation is the best?" Which is not ok because you are just asking for an opinion about why each one thinks his own version is the best. Hope that makes sense. Commented Jun 6, 2018 at 16:08

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Actually I knew about this approach but I didn't want to do it because that's a lots of work for each page and I just wanna deliver my project ASAP Do you have any comment about creating view that can fetch all data in whole from multiple tables and let hibernate fetch those data ?
what I mean by view is database view
Just create your database view like you normally would and then either (1) create an entity that maps to your view, marking the entity as @Immutable given that the data comes from a view and you shouldn't try to change it via the application or (2) use a Tuple-based query to fetch the data from the view. There's plenty of information about this already on Stack Overflow or the net.
thanks Naros, I already master of this with Hibernate! Actually I went ahead with componentized solution together with JQuery asynchronous request and I think this is the most systematic solution, and it's working very fine for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.