Here are few straight cases where we need type conversion: Case #1. To help simplifying bean configurations, Spring supports conversion of property values to and from text values. Each property editor is designed for a property of certain type only. And to put them in use, we have to register them with Spring container. Case #2. Also when using Spring MVC, controllers binds the form field values to properties of an object. Suppose the object is composed with another object, then the MVC controller cannot automatically assign values to the internal custom type object as all the values in the form are inputted as text values. Spring container will take of conversion of text values to primitive types but not to custom type objects. For this to be taken care, we have to initialize custom editors in the MVC flow.
This article will discuss the various ways of implementing the converters for custom type objects. Continue reading →
Serialization is all about saving the state of a given object and reconstructing the object back when it is needed. As it is all about saving state of an instance, it is clear that none of the static variables would get serialized as part of the process. Also when we want few variables defined in an object not to be serialized, we mark them as transient. For ex: we don’t want to serialize a database connection. Continue reading →
A natural id is a property or a set of properties that would identify an entity uniquely. We can have at-most one natural id defined for an entity. When Hibernate sees natural-id tag in an entity mapping file, it automatically creates unique and not-null constraints on the properties constituting natural-id. Continue reading →
Spring, on initializing application context, creates proxies when it comes across classes marked with @Transactional. @Transactional can be applied at class level or method level. Applying it at class level means all the public methods defined in the class are transactional. The kind of proxy Spring creates i.e. Jdk Proxy or CGLIB proxy, depends on the class in which the method is marked transactional. Continue reading →
In Spring, most of the beans we work with are Singletons. If a singleton bean is wired with yet another singleton bean, there is absolutely no problem. But if it is wired with a bean which is of different scope, say prototype, how does it work? Here is the example:
Singleton pattern is one of the most widely used design patterns. When a class is called Singleton, there is only one instance created for it and it forms the global point of contact. This is implemented by making the constructor private and getInstance() method is given the responsibility of providing the access to the singleton object created. This can be pretty straight forward when we work in a single threaded environment. But when we have multiple threads, ensuring single instance creation can be little trickier. In this article I will discuss the multiple ways of creating a Singleton Class