Architecture and Data Blog

Thoughts about intersection of data, devops, design and software architecture

ID generation with ORM's Table, Sequence or Identity strategy

In this blog post, I will discuss ID generation techniques using the Object Relation Mapping frameworks such as Hibernate, Toplink, ActiveRecord, Entity Framework. When using hibernate or any other ORM mapping framework. There is a need to generate primary key values for the “id” columns. These values can be generated by using IDENTITY, SEQUENCE or TABLE strategies. Generating custom values for primary keys or other values is a topic for another blog post.

Using liquibase to load data and ignore some columns

Loading data into tables is needed many times on projects to load test, Liquibase provides a method to load data into tables with lots of customization. In the example shown below, I’m loading zip code data with the following column layout


Transactions using Groovy.SQL with Spring annotations and connection pools

When using Groovy with Spring framework, interacting with the database can be done using the Groovy.SQL class which provides a easy to use interface. When using Groovy.SQL, if we have a need to do transactions, we have the .withTransaction method that accepts a closure, to which we can pass in code to execute within the transaction. In our project since we were using spring already, using annotations to define transactions would be a great.

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<Movie> findByQReferenceId(Long id) { final SimpleExpression matchesId = Property.forName("qReferenceId").eq(id); DetachedCriteria criteria = DetachedCriteria.forClass(Movie.class); criteria = criteria.add(matchesId); List<Movie> movies = (List<Movie>) getHibernateTemplate().