1

I have a domain object,defined as :

@AllArgsConstructor
@NoArgsConstructor
@ToString
@Getter
@Setter
@Entity
@Table(name = "t_domin")
@Builder
public class Domain {

  @Column(name = "BUSINESS_DATE")
  private LocalDateTime businessDate;

  @Column(name = "DATA_PROVIDER")
  @Enumerated(EnumType.STRING)
  private DataProvider dataProvider;

}

For the above domain Object I've Spring Repository:

@Repository
public interface DomainRepository extends JpaRepository<Domain, UUID> {

  List<Domain> findByBusinessDate(LocalDateTime businessDate);
}

when I'm querying : repository.findByBusinessDate(someDate) --> I get 1000 records in more than a minute,where as same query if I run on db(oracle) I get the result-set within a sec.

I turned on the log (TRACE) ,I see that its taking more time in extracting the result set into list of java object:

TRACE o.h.type.descriptor.sql.BasicExtractor

How can i tune the performance ?

Zeromus
  • 4,472
  • 8
  • 32
  • 40
Ankit
  • 51
  • 1
  • 6
  • Does the SQL sent to the database by the Hibernate is **exactly** the query that you run on db? No only the SQL, [but the parameters](https://stackoverflow.com/a/27727591/2387977). Also, try to remove all `Lombok` annotations only to isolate the real cause. Show us the version of Hibernate are you using too, because the LocalDateTime is not [fully supported](https://www.thoughts-on-java.org/hibernate-5-date-and-time/) in some versions. – Dherik Mar 30 '18 at 11:53
  • Yes,I ran the same query on db which is generated by Hibernate.I'm Using Hibernate 5.2. I don't think lombok is causing side effect on performence – Ankit Mar 30 '18 at 13:10
  • My main concern is the `@AllArgsConstructor`. Try to remove it and test again. – Dherik Mar 30 '18 at 16:08
  • @AllArgsConstructor is required when Builder is used with NoArgsConstructor – Ankit Apr 02 '18 at 08:44

1 Answers1

1

Hibernate default fetch size is 10 ,which was causing the issue . For large result sets, it’s important to increase the fetch size,so by changing the fetch size at query level its become really faster.

@QueryHints(@javax.persistence.QueryHint(name = "org.hibernate.fetchSize", value = "1000"))
List<Domain> findByBusinessDate(LocalDateTime businessDate);

If you want it globally add this in your property file:

hibernate.jdbc.fetch_size:1000
Ankit
  • 51
  • 1
  • 6