ORM frameworks like Hibernate and other JPA implementors can significantly simplify development of persistence layer. Introducing entity abstraction level helps to model clean business domain and to hide underlying SQL statements used to achieve persistence of the domain. Such approach is especially useful in large domains, since developer no longer needs to create and maintain all SQL statements used by application.
Just a few JPA annotations like
@Entity
/@ManyToOne
/@OneToMany
etc. on the domain classes and EntityManager
or custom repositories to obtain domain aggregate roots, and you are ready to go. Having that, the vast majority of use cases involving persistence can be handled in domain model by JPA cascades and traversing associations and performing operations on them.
Everything comes with a price. In exchange for clean and easy development, some issues can arise sooner or later:
FetchType.EAGER
on associations)In next steps I’ll show the new approach how these problems could be detected, but first let’s see to classic way.
#java #jpa #sql #spring-boot #performance #lazy-loading #jplusone #hibernate