Hibernate needs to identify which entities in the Session has been changed, in other words become dirty in the meantime, so that it can issue an update sql statement to reflect those changes into the database. The default mechanism to identify dirty entities is to compare each attribute one by one with the snapshot kept […]
Author: Kenan Sevindik
Is It Possible To Change Entity Fetch Strategy During Hibernate Merge?
When I talk with my colleague about my experience with Hibernate merge behavior on lazy associations with cascade type merge, he suggested me to check if Hibernate allows us to change fetch logic it applies on detached entities during merge operation. That way, it would be possible to suppress eager initialization of those associations during merge. Hibernate […]
More about Eager Initialization of Lazy Associations During Hibernate Merge
After reading my blog post about eager initialization of lazy 1:1 or M:1 associations because of the cascade merge attribute, someone asked about if it applies for 1:M and M:N associations as well? The answer is, yes it applies. Let’s create another small entity in order to illustrate that case as well. @Entity @Table(name=”T_BAZ”) public […]
Hibernate Merge may Cause EAGER Initialization of LAZY OneToOne Associations
Let’s have following two simple entities, having 1:1 lazy association between each other. @Entity @Table(name=”T_FOO”) public class Foo { @Id @GeneratedValue private Long id; @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) @JoinColumn(name = “bar_id”) private Bar bar; public Long getId() { return id; } public Bar getBar() { return bar; } public void setBar(Bar bar) { […]
Feature Interaction Problems and Spring Security
Feature interaction problem is something that features work smoothly and without any problem in your system individually; however, problems arise with those features when you bring them together. Bertrand Meyer has recently published his thoughts about the topic as well. While reading on it, I’ve come to realize that Spring Security has several similar issues […]
Weird Rollback Behavior of Spring TestContext Framework
One of the nice features of TestContext module of Spring Application Framework is its ability to run unit tests within a transaction context. By that way, you are able to both execute your persistence operations which usually expect an active transaction to run, and also rollback state changes occur during execution of these persistence operations […]
When It is Useful to Make Use of JPA @MapKey?
As you probably know, JPA provides way to map collection associations using java.util.Map. However, usage scenarios for such mappings are very limited; but when it comes, they become highly invaluable to easily extract necessary information from your domain model. They are especially useful in order to categorize entities in your associated collection based on some […]
How to populate your DB with sample data during Hibernate bootstrap?
One of the undocumented features of Hibernate is its execution of SQL scripts given within a special file during bootstrap process. It is a very useful feature in order to populate your DB with sample data during testing or development mode. If you create a file named import.sql under project’s root classpath, and put […]
Activating Authorization Success Event Publish Feature
Spring Security publishes various authentication and authorization events during its security checks. Spring managed beans which implement ApplicationListener interface or beans with methods annotated with @EventListener can consume those events within the application. One of those security related events is AuthorizedEvent which indicates that user request is allowed to access secure web resource. It is, […]
Configuring Vaadin without web.xml
There is always room for improvement in programming world. After my initial post about configuring Vaadin in 6 simple steps, one of my friends indicated that we could have used annotation based configuration to get rid of web.xml in our Vaadin configuration. Yes, he is right. It is possible to configure Vaadin with annotations without […]