Imagine having a tool that can automatically detect if you are using Java Persistence and Hibernate properly.
No more performance issues, no more silly mistakes that can cost you a lot of time and money.
Now, you have this tool. It's called Hypersistence Optimizer.
So, assuming you have an entity like the following one:
@Entity(name = "PostComment")
@Table(name = "post_comment")
public class PostComment {
@Id
private Long id;
@ManyToOne
private Post post;
private String review;
}
Hypersistence Optimizer will log the following error message when scanning this entity:
ERROR [main]: Hypersistence Optimizer - CRITICAL - EagerFetchingEvent -
The [post] attribute in the [io.hypersistence.optimizer.hibernate.mapping.association.fetching.eager.EagerFetchingManyToOneTest$PostComment] entity uses eager fetching.
Consider using a lazy fetching which, not only that is more efficient, but it is way more flexible when it comes to fetching data.
If you want to play with it, you need to install the library which is available here.
Afterwards, if you want to play with it, you can use the hypersistence-optimizer-test-case
module and run the EagerFetchingManyToOneTest
test class which uses the aformentioned PostComment
entity mapping.
If you'd like to create a new issue, be it a feature request or simply reporting a bug, then you can use this GitHub repository issue list.
For bugs, please provide a replicating test case. You can use the EagerFetchingManyToOneTest
as a template to create your new test case scenario.
When you are done, please send your test case as a Pull Request, and I'll take care of it.
And, thank you for using this tool and for wanting to make it even more awesome.
If you are using Spring, you can try the JPA or Hibernate modules.
The hypersistence-optimizer-spring-jpa-example
shows how you can integrate the Hypersistence Optimizer with a Spring JPA application.
final ListEventHandler listEventListener = new ListEventHandler();
new HypersistenceOptimizer(
new JpaConfig(
entityManager.getEntityManagerFactory()
)
.setEventHandler(new ChainEventHandler(
Arrays.asList(
listEventListener,
LogEventHandler.INSTANCE
)
))
).init();
The hypersistence-optimizer-spring-hibernate-example
shows how you can integrate the Hypersistence Optimizer with a Spring Hibernate application.
final ListEventHandler listEventListener = new ListEventHandler();
new HypersistenceOptimizer(
new HibernateConfig(
sessionFactory
)
.setEventHandler(new ChainEventHandler(
Arrays.asList(
listEventListener,
LogEventHandler.INSTANCE
)
))
).init();
It's as simple as that!
Enjoy running you data access layer at warp speed now.