Note that there are some explanatory texts on larger screens.

plurals
  1. POJpa , Hibernate select query optimization
    primarykey
    data
    text
    <p>I am new to JPa / Hibernate. We are using JPA with hibernate in our application. Currently i observed that performing select query on table with criteria, hibernate perform select query for each row.</p> <p>So my question is , how hibernate perform search on table and retrieves records ?</p> <p>I have a scenario where i need to find active users and perform filers on active user list , like recently logged in users, most popular user(based on some criteria) for example i have 100 active users of which 20 users are recently logged in. 20 users are most popular.</p> <p>if i have to fetch records from database , when i query with active users , hibernate perform 100 select operations.(with table scan)</p> <p>and if i perform 2 seperate queries for recent and most popular users hibernate will perform 20 + 20 = 40 select operations. (but with 2 times table scan)</p> <p><strong>so how hibernate fetches records from database ?</strong> if i compare with jdbc , i would say by getting active pitches and performing filters on it i will be doing 1 time table scan.</p> <p>but with hibernate it performs more select operations and it queries less select when i do individual selects for recent and most popular users ,even when i do 2 time table scan !</p> <pre><code>@ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "fk_profile_id", referencedColumnName = "pk_id") private Profile Profile; @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "investmentPitch", targetEntity = InvestmentType.class, orphanRemoval = true) private List&lt;InvestmentType&gt; investmentType; @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "investmentPitch", targetEntity = TabDetail.class, orphanRemoval = true) private List&lt;TabDetail&gt; TabDetail; @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "investmentPitch", targetEntity = Address.class, orphanRemoval = true) private List&lt;Address&gt; Address; @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.DETACH) @JoinTable(name = "pitch_sector", joinColumns = { @JoinColumn(name = "fk_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "fk_sector_id", nullable = false, updatable = false) }) private List&lt;SectorMaster&gt; sectors; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload