Recently in Open Source Category

Hibernate weirdness with property names

Consider this Hibernate mapping

@Column(name = "qReferenceId")
public Long getQReferenceId() {
return qReferenceId;
}

Where qReferenceId is data provided to our application via a external reference, we do not have a QReference Object or Table for FK references.When trying to query this object using DetachedQuery, this Simple expression was used.

public List findByQReferenceId(Long id) {
     final SimpleExpression matchesId = Property.forName("qReferenceId").eq(id);
    DetachedCriteria criteria = DetachedCriteria.forClass(Movie.class);
    criteria = criteria.add(matchesId);
    List movies = (List) getHibernateTemplate().findByCriteria(criteria);
    return movies;
}

When running this method, I kept getting errors shown below.


could not resolve property: qReferenceId of: com.example.Movie;
nested exception is org.hibernate.QueryException: could not resolve property: qReferenceId of: com.example.Movie
....
....

I thought I had a spelling mistake on the property name and also tried many other combinations. Finally I said why not use "QReferenceId" and suddenly everything was hunky dory, this kind of weirdness does not happen when working with property names that do not have consecutive double uppercase characters in the getter/setter for the property. very interesting. So this method worked

public List findByQReferenceId(Long id) {
    final SimpleExpression matchesId = Property.forName("QReferenceId").eq(id);
    DetachedCriteria criteria = DetachedCriteria.forClass(Movie.class);
    criteria = criteria.add(matchesId);
    List movies = (List) getHibernateTemplate().findByCriteria(criteria);
    return movies;
}

Database Migration Utility

I have taken up the hobby of searching the opensource landscape for tools that help me do Agile database development. I'm going to write about all the Tools that I come across that help me, my preference is opensource software but not limited to it. I will try to provide some sound examples and share my experiences with all that tools that I come across and share the example code I used.

Migrate DB

This is a simple xml based solution that applies all the changes defined by you in the XML file, you provide a pre-condition or test condition for the execution of the sql and the SQL is executed when the condition is met. The tool provides command line support and also gives ANT integration.

lets take this example build file I'm using this build.properties file to define my connection properties

I created a ANT task named as dbrelease, used the ANT task to create a ANT target named as migratedb. The ANT target uses a XML file to write a pre condition SQL and the actual SQL to migrate the DB. example XML can be found here.

Full example can be found here ( is a zip file and contains the migratedb.jar all the xml files and is setup to work with oracle)

All Content Copyright © 2012 Pramod Sadalage. All Rights Reserved.