Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance overhead for Hibernate and Spring due to reflection

Spring and Hibernate uses reflection for bean creation (in case of spring) and POJO mapping (in case of Hibernate). Does it negatively impacts on performance ? Because reflection is slower compare to direct object creation.

like image 211
Silent Warrior Avatar asked Jun 10 '09 06:06

Silent Warrior


People also ask

Does hibernate use reflection?

Although hibernate uses reflection to obtain data, it still needs to know which elements of an object should be persisted, what their types are and where to put the data when it obtains it (e.g. which database table to put the data in).

What is LAZY loading in Spring JPA?

With a LAZY type dependency, only data of the wanted object is loaded: author's data is not retrieved. With Spring Data JPA, every relationship between 2 domain objects owns one of these data loading types. By default, the method will be determined by the relationship type.


1 Answers

Yes, it probably does. Hibernate is pretty heavily optimised in various cunning ways, but it will still be slower than low-level data access with exactly the right prepared statement, assuming the cache doesn't help you.

But that's not the question you need to ask anyway.

You need to ask whether it affects performance significantly - at which point I suspect you'll find the answer is "no". In terms of Hibernate, the underlying database access is likely to be a lot slower than the overhead due to Hibernate. In terms of Spring, the bean creation often happens only at the very start of the program, a single time.

As always, if you have concerns, benchmark and profile a realistic scenario.

like image 129
Jon Skeet Avatar answered Oct 02 '22 19:10

Jon Skeet