Tuesday, February 27, 2007

Hibernate Criteria

DetachedCriteria criteria = DetachedCriteria.forClass(MyObject.class);
criteria.add(Restrictions.ge("prop1Name", valueObject);
criteria.add(Restrictions.eq("prop2Name", valueObject);
//getHibernateTemplate() returns org.springframework.orm.hibernate3.HibernateTemplate
List list = getHibernateTemplate().findByCriteria(criteria);

Monday, February 26, 2007

Spring Basics

GET BEAN OUT OF SPRING CONFIG FILE

//define location of the config files referenced by the bean(s)
ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext(
new String[]{"classpath*:config1.xml",
"classpath*:/subdir/config2.xml",
"classpath*:etc.xml"});
//get the bean
MyBean myBean = (MyBean)springContext.getBean("myBeanName");

Friday, February 23, 2007

Buzz Stuff

Saas is a new, or maybe not so new buzz word. It stands for Software as a service. It's a web 2.0 rendition of ASP. Of course, there are new characteristics and subtleties attached, but concepts are pretty similar.
As always, wikipedia has the best definition

On-demand Software is a software that runs across the internet in a software as a service model (no software to install).

Service Oriented Architecture (SOA) aims to simplify integration and increase agility by creating well defined and standards-based boundaries between systems.

Apache Collection Utilities

CollectionUtils, SetUtils, Predicates, etc.
o'reilly reference

Friday, January 26, 2007

Hibernate - map column to a non-existent java property

On rare occasions, I had to populate a database column that doesn't have a matching property in the object model. Say, I have a not null column INTERFACE_ID and value for this column is derived based on some logic. Here is how I worked around it in Hibernate.

1. Create implementation of a UserType that has logic to derive a value for interface_id
2. Use the following mapping

<property name="interfaceId" column="INTERFACE_ID" access="noop" update="false" null="false" type="SomeUserTypeImplementation"/>

3. A few things to note...
⇒ name attribute is any madeup value
⇒ acces="noop" tells hibernate not to look for an object property for this column
⇒ not-null="false". noop columns must be defined as nullable
⇒ update="false". noop columns cannot be updated