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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With