Welcome

A Slight Difference Between Autowire byType and constructor

Spring documentation states that both autowire byType and constructor modes expect at most one bean definition in the ApplicationContext, so that it can be autowired into the depending bean. Here is the excerpt taken from Spring Reference Documentation Table 6.2. Autowiring modes; byType Allows a property to be autowired if exactly one bean of the […]

A Transaction Gotcha When Using Spring with Hibernate

Spring’s transaction propagation rule SUPPORTS states that if there exists a transaction when the method is called, it should work within that transaction, otherwise it should work outside any transaction. Similarly, transaction propagation rule NOT_SUPPORTED states that if there exists any active transaction when the method is called, that active transaction should be suspended before […]

What is the difference between Strategy and Template Method patterns…, if there is any?

In our Spring book, we discuss about transaction management mechanisms available in the Spring Framework, namely declarative and programmatic transactions. It is further explained inside programmatic transaction demarcation section, that how programmatic transaction can be achieved using different methods. One of the ways programmatic transaction can be achieved is, using TransactionTemplate utility class provided by […]

Things to Fix When Upgrading from Spring Security 3.2.x to 4.x

Some things have been changed in Spring Security 4.x compared to previous 3.2.x branches. They are not overwhelming but you may have to deal with them so that your application can work without any problem after upgrading to Spring 4.x release. I noted them down during my upgrade process, and post here in case you […]

Moving libraries of web apps into shared folder

If you plan to move repeating libraries of your several web applications depend on, to a shared folder of your application server, I would definitely say NO! to this request. One of my clients asked me about to centralise such repeating libraries into a shared folder. Actually, I had written another blog post in which […]

Possible bug in Hibernate XML based mapping when using properties element

Assume you have a Person with firstName and lastName properties, and a subclass of it called as Vet. You will have hbm.xml mapping files with the following content. Person.hbml.xml <hibernate-mapping> <class name=”com.javaegitimleri.petclinic.model.Person” table=”persons” abstract=”true”> <cache usage=”read-write” /> <id name=”id” column=”ID” access=”field”> <generator /> </id> <version name=”version” column=”VERSION” type=”integer” access=”field” /> <properties name=”firstAndLastName” unique=”true”> <property name=”firstName” […]

Error while generating JAXB Classes from XSD File

You may get following error when you try to generate JAXB classes from your XSD files within Eclipse IDE. Error: Could not find or load main class com.sun.tools.internal.xjc.XJCFacade The reason for this error is that you have configured Eclipse to use JRE instead of JDK. If you add a JDK through Window>Preferences>Java>Installed JREs, and select […]

How to Switch from One DB Instance to Another at Runtime

Sometimes we may need to switch from one db instance from another during runtime. Actually this is very easy if you are using Spring and DataSource API in order to obtain DB connections. Lets look at our solution for such a requirement. Our solution lays on “proxy pattern“. Spring provides us with ProxyFactoryBean so that […]

Be Careful When Using Parent-Child Associations in Hibernate

Parent-child relationships are a special case of more general 1:M associations. They are simply part-whole relationships and for Hibernate it is not meaningful that parts (childs) should exist without belonging a whole (parent). Parent-child association is specified with orphanRemoval attribute of @OneToMany annotation. Hibernate achieves this by employing a special persistent collection implementation. First thing […]

Hibernate’s New Feature For Overcoming Frustrating LazyInitializationExceptions

For many years LazyInitializationExceptions have become most frustrating point of Hibernate. This exception occurs when you try to access an un-initialised lazy association of a detached entity. In general, entities become detached in three different ways; session close session clear session evict You have to be sure that any lazy attributes you will access be […]