MongoDB optimistic locking
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
Introduction
When moving from JPA to MongoDB you start to realize how many JPA features you’ve previously taken for granted. JPA prevents “lost updates” through both pessimistic and optimistic locking. Optimistic locking doesn’t end up locking anything, and it would have been better named optimistic locking-free or optimistic concurrency control because that’s what it does anyway.
Lost updates
So, what does it mean to “lose updates”?
A real-life example would be when multiple background tasks update different attributes of some common Entity.
In our example, we have a Product Entity with a quantity and a discount which are resolved by two separate batch processors.
- the Stock batch loads the Product with {quantity:1, discount: 0}
- the Stock changes the quantity, so we have {quantity:5, discount: 0}
- the Discount batch loads the Product with {quantity:1, discount: 0}
- the Discount changes the discount, so we have {quantity:1, discount: 15}
- Stock saves the Product {quantity:5, discount: 0}
- Discount saves the Product {quantity:1, discount: 15}
- the saved quantity is 1, and the Stock update is lost
In JPA you may provide the @Version field (usually an auto-incremented number) and Hibernate takes care of the rest. Behind the scenes, there is a safety mechanism that checks the updated rows number when given a specific version. If no row was updated, then the version has changed and an optimistic locking exception is thrown.
Open-minded architect
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
While chit-chatting with one of my colleagues, I was surprised to hear they use a PHP team for developing their front-end application, while the back-end services are implemented using Java. Since their project is doing great, this really got my thinking why I haven’t ever considered such an architecture.
Most large Java web application I’ve been involved with have shone on the server-side part, while the client-side has been the Achilles heel.
While you can find great Java web developers, not every Java developer has web-based skills. But PHP developers are great when it comes to web programming, and they don’t have a zillion of frameworks to specialize in. PHP developing is pretty much standard, as opposed to Java web programming. I have always been anxious when joining a project using a new web framework I didn’t know anything about (e.g. Wicket), but that’s not the case for a PHP developer. They can always join a new project, and the learning curve is not that steep.
I remember reading many comparisons tests for Java vs PHP or Python, and I don’t remember seeing a single test not aiming to pick-up a winner. Such test targets only the language, but disregards the community and especially its developers.
Sometimes the winning solution is not a single technology but a clever mix of those that are best suited within a given context. A similar concept is the polyglot persistence.
So as an architect you always have to stay open-minded and be objective of any technology you happen to love. After all, I love Java, but I also know it’s not always the best solution to all my clients’ problems.

Batch processing best practices
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
Introduction
Most applications have at least one batch processing task, executing a particular logic in the background. Writing a batch job is not complicated but there are some basic rules you need to be aware of, and I am going to enumerate the ones I found to be most important.
From an input type point of view, the processing items may come through polling a processing item repository or by being pushed them into the system through a queue. The following diagram shows the three main components of a typical batch processing system:
- the input component (loading items by polling or from an input queue)
- the processor: the main processing logic component
- the output component: the output channel or store where results will sent
21st century logging
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
I think logging should get more attention than we are currently giving it. When designing an application a great deal of effort goes into modeling the customer business logic, making sure all use cases are covered and handled properly. The business model is mapped to a persistence storage (be at a RDBMS or a NoSQL solution), frameworks are being chosen: web, middle-ware, batch jobs, and probably SLF4J with log4j or logback.
This has been the case of almost all applications I’ve been involved with, and logging was always a second-class citizen, relying on good old string logging frameworks for that.
But recently I come to realize there is much more to logging than the current string based logging systems. Especially if my system gets deployed in the cloud and takes advantage of auto-scaling, then gathering text files and aggregating them to a common place smells like hacking.
In my latest application, we implemented a notification mechanism that holds more complex information since the String based log wasn’t sufficient. I have to thank one of my colleagues I work with who opened my eyes when saying “Notifications are at the heart of our application”. I haven’t ever thought of logging as the heart of any application. Business Logic is the heart of the application, not logging. But there is a lot of truth in his words since you can’t deploy something without a good mechanism of knowing if your system is actually doing what it was meant for.
How to implement Equals and HashCode for JPA entities
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
Introduction
Every Java object inherits the equals and hashCode methods, yet they are useful only for Value objects, being of no use for stateless behavior-oriented objects.
While comparing references using the “==” operator is straightforward, for object equality things are a little bit more complicated.
How to fetch entities multiple levels deep with Hibernate
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
Introduction
It’s quite common to retrieve a root entity along with its child associations on multiple levels.
In our example, we need to load a Forest with its Trees and Branches and Leaves, and we will try to see have Hibernate behaves for three collection types: Sets, Indexed Lists, and Bags.
A beginner’s guide to Hibernate fetching strategies
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
Introduction
When it comes to working with an ORM tool, everybody acknowledges the importance of database design and Entity-to-Table mapping. These aspects get a lot of attention, while things like fetching strategy might be simply put-off.
In my opinion, the entity fetching strategy shouldn’t ever be separated from the entity mapping design, since it might affect the overall application performance unless properly designed.
Before Hibernate and JPA got so popular, there was a great deal of effort put into designing each query, because you had to explicitly select all the joins you wanted to select from, and all the columns you were interested in. And if that was not enough, the DBA would optimize the slow running queries.
In JPA times, the JPQL or HQL queries are fetching Entities along with some of their associated relationships. This eases development, as it frees us from manually choosing all table fields we are interested in, and sometimes joins or additional queries are automatically generated for serving our needs.
This is a double-edged sword. On one hand, you can deliver features faster, but if your automatically generated SQL queries are not efficient, your overall application performance might suffer significantly.
Had this problem this morning fixed from stackoverflow than found this. Thx Vlad Mihalcea for a concise explanation to speed up development & production issues !!!
— Gal Levinshtein (@gkodkod) September 17, 2018
Hibernate fetching strategies - using #JPA and @Hibernate @vlad_mihalcea https://t.co/Dwf1ZPPpV0
A beginner’s guide to Hibernate flush operation order
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
Introduction
As explained in this article, Hibernate shifts the developer mindset from SQL to entity state transitions. A JPA entity may be in one of the following states:
- New/Transient: the entity is not associated with a persistence context, be it a newly created object the database doesn’t know anything about.
- Persistent: the entity is associated with a persistence context (residing in the 1st Level Cache) and there is a database row representing this entity.
- Detached: the entity was previously associated with a persistence context, but the persistence context was closed, or the entity was manually evicted.
- Removed: the entity was marked as removed and the persistence context will remove it from the database at flush time.
Moving an object from one state to another is done by calling the EntityManager methods such as:
persist
merge
remove
Cascading allows propagating a given event from a parent to a child, also easing managing entities relationship management.
During the flush time, Hibernate will translate the changes recorded by the current Persistence Context into SQL queries.
How do Set and List collections behave with JPA and Hibernate
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
Introduction
Hibernate is a great ORM tool, and it eases development considerably, but it has a lot of gotchas you must be aware of if you want to use it properly.
On medium to large projects, it’s very common to have bidirectional parent-child associations, which allow us to navigate both ends of a given relationship.
When it comes to controlling the persist/merge part of the association, there are two options available. One would be to have the @OneToMany
end in charge of synchronizing the collection changes, but this is an inefficient approach.
The most common approach is when the @ManyToOne side controls the association and the @OneToMany end is using the “mappedBy” option.
I will discuss the latter approach since it’s the most common and the most efficient one, in terms of the executed queries number.
Book Review – How to win friends and influence people
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
Soft skills
When working as a Scrum Master you have to constantly make sure the Scrum principles are followed, but there are also other aspects that requiring handling as well, and they are more subtle yet equally important for successfully managing developing teams.
I am talking about soft skills such as managing team conflicts, encouraging people, knowing how to challenge your team members. There are times when some of your guys behave inappropriately versus others, or their attitude/behavior is counter-productive and you have to step in and correct these problems with diplomacy and keen tact.
If you are not endowed with people handling skills, don’t despair, there is still hope. I don’t believe those telling these skills can’t ever be acquired and that you have to be born with them. With proper training, you can improve yourself sufficiently enough to be able to manage your team efficiently,
So, I will present you a great book that offers old solutions to new problems.