Welcome

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 […]

Spring ve Tapestry’de IoC Yaklaşımları 2

İlk bölümde Spring ve Tapestry Framework’lerini IoC container oluşturma kabiliyetleri ve bağımlılıkların enjekte edilmesi konuları üzerinde durmuştuk. Bu bölümde ise kaldığımız yerden bean’ların scope yönetimi ile devam edelim. Scope Yönetimi Tapestry’de varsayılan olarak servisler’in scope’u Spring’de de olduğu gibi Singleton olarak belirlenmektedir. Yani servis için tek bir instance yaratılmakta ve tüm threadler bu instance’i kullanmaktadır. […]

Another Difference Between Autowire byType and constructor

Lets keep playing with autowiring behaviour of Spring Framework. Autowire byType or byName is not required by default. In other words, they will do nothing if they cannot find suitable candidates to inject into target beans. They can be made required in two different ways; One is to use @Required annotation in setter method if […]

Weird Autowiring Behaviour in Spring Framework

During lab sessions in our Enterprise Java trainings I usually leave the main track of lab outlines and start trying various cases related with the topic. It is a bit risky for me but it also becomes beneficial for attendees in terms of learning by experimenting with the framework. The risky point is that I […]

TransactionTemplate and Rollback Rules

When I was playing with TransactionTemplate during one of my Spring training sessions, I promptly suggested audience with trying to change default rollback rules while using TransactionTemplate. After all TransactionTemplate encapsulates boilerplate transaction begin, commit/rollback statements and we only give business logic part which it executes inside that begin…commit/rollback block. Because of this, I’ve thought […]

How to build SessionFactory in Hibernate 4

Well, I think it is the first time in Hibernate’s history that it is released with incomplete feature implementations and documentation. I came to this conclusion when I see Configuration.buildSessionFactory() method as deprecated. When I look at documentation however it still uses above method to create it! If you look at org.hibernate.cfg.Configuration class, it is […]

StringHttpMessageConverter DEFAULT_CHARSET Limitation for Turkish Content

Spring has its own REST support known as Spring Web MVC. Although, I am happy with its general capabilities, I came up with a small but very annoying problem or let’s say limitation related with its one of HttpMessageConverter‘s classes. Spring Web MVC make use of HttpMessageConverter classes both on server and client to handle […]

Sorting Your Beans With Spring OrderComparator

Sometimes you may need to execute your collection of beans in a a specified order. For example, in one of our projects, we have collection of EventHandlers which operate on when certain Events occur. For each event there might be more than one EventHandler instance that need to operate on. Most of the time it […]