Configuring Hibernate and Spring for JTA

Posted by Maarten Winkels mid-afternoon: July 18, 2008

Spring is a great framework for dependency injection and it comes with a lot of support classes and utilities for all kind of things. Hibernate is a persistence service with a lot of useful features, that is relatively easy to use. Configuring both frameworks is not always easy. Configuring them together is sometimes hard and it is easy to make mistakes.

This blog addresses a problem in a configuration that is fairly common: use Spring for transaction management on top of a JTA provider and use Hibernate for persistence. Transaction demarcation is easy and declarative with Spring. The problem is that Hibernate sometimes needs to detect the current transaction and this needs to be configured. This leads to hard to detect bugs in applications that rely on auto flushing.
(more...)

Back to the 80’s…

Posted by Twan van Enckevort in the early afternoon: July 15, 2008

Overview of the CTA display and the PC that runs the socket server allowing tcp/ip access to the display

One of the challenges we are facing in our project is connecting antique display devices to the brand new travel information system we are building. If you have traveled by train in the Netherlands you are familiar with them: large displays with booklets for destinations and departure times. It contains a number of booklets which are controlled by a stepper engine. The devices are called CTA's, were developed in the eighties and are a solid piece of engineering. Behind the track indicator, which doubles as a door, is a temperature control for the heating, a power socket for connecting electrical equipment, a telephone socket and a connector for testing. Oh yes, did I mention it is heavy?

(more...)

A thing I was playing with today was many-to-many relationships in Grails to create a Tag Cloud. To create a Tag Cloud, I must have a set of key/value pairs, each with a label and a value of the label, which could look like this:

['Java': 5, 'Grails': 16, 'Groovy': 12]

But to query this, I need to query a many to many relationship and produce the above result. This blog will describe how to do this with HQL, Criteria and the HibernateCriteriaBuilder.
(more...)

Advanced Hibernate: Proxy Pitfalls

Posted by Maarten Winkels in the late evening: March 8, 2008

Most programmers come into contact with Hibernate proxies when they face the ominous LazyInitializationException. The bad taste is hard to wash away, but Proxies are a necessary “evil” when working with Hibernate. This article will dig into why proxies are important. It will also point out some pitfalls that occur often when working with proxies.
(more...)

Appfuse 2.0 Review

Posted by Balaji D Loganathan mid-afternoon: March 1, 2008

AppFuse is an open source project and application that uses open source tools built on the Java platform to help you develop
web applications quickly and efficiently.

In a typical web application, it is common to have a login screen, registration screen, content storage in database, security and most importantly testing.

When building a Java web application, we might start adding one jar file after another to implement a particular user story.

For example, if i want to have ACEGI security for my web app, I might download ACEGI jar, map and configure it in web.xml and security.xml files.

What if, there exists a toolkit that already provides these common features to us. ?
(more...)

Advanced Hibernate, Maps Part 2: Query by Lazy Map

Posted by Maarten Winkels around lunchtime: December 14, 2007

Hibernate is a very mature and feature rich product that can be used to solve a lot of basic or advanced problems. One of its core features is the ability to map collections. If an entity contains a collection, for example a Map, Hibernate will map the entity and the map onto a relational structure (a number of tables) and allows the application to navigate through the collection without having to make explicit JDBC calls. Hibernate will under the hood perform the correct queries to fetch the data or even update rows in the database according to changes made by the application on the data structure in memory.

But what if you have a very large collection that you need to search for a single entry? For example, say the system is used to fetch the PostalCode a particular Street in a City. Fetching the complete collection of Streets and PostalCodes just to find out the PostalCode for a single street is not a very attractive idea. The normal approach would probably be to use a DAO and make an explicit query. Apart from the problem of getting the DAO object injected into the City entity, using a lazy Map is a more elegant solution.

(more...)

Advanced Hibernate, Maps Part 1: Complex Associations

Posted by Maarten Winkels mid-morning: October 22, 2007

When it comes to using Hibernate, most projects only use the very basic features. This is mostly due to naivety or unfamiliarity with the product. Hibernate is a very mature and feature rich product that can be used to solve a lot of basic or advanced problems. I think the point here is to put the complexity at the right level: You can always take a very basic approach to using Hibernate and solve the mismatch between your mapping and your model in your model, but that would put complexity in your model that is basically boilerplate code. It is only there because the persistence layer is not used correctly. If you make the persistence layer (in this case the Hibernate mapping) more complex it will be harder to maintain, but your model code will be more concise and easier to understand.

One of the features of Hibernate that is hardly ever used, but has some very interesting applications is the ability to map java.util.Maps. This blog will show an application of using a Map in your model and mapping that model with Hibernate to a Relational Database Schema.

(more...)

Mapping MultiMaps with Hibernate

Posted by Maarten Winkels in the early morning: October 5, 2007

Hibernate is a very complete ORM library. One of the few ommisions is the possibility to map collections of collections. In this blog this omission is investigated and a solution is provided for the specific case of a Map of Sets.
(more...)

Hibernate component (value object) inheritance mapping

Posted by Priyanshu Goyal around lunchtime: September 25, 2007

Entity inheritance mapping in Hibernate can easily be done by following one of the three strategies and many a times instance of which subclass has to be created is identified by the value of the discriminator column (particularly in the case of table per class hierarchy). For such mappings there is already an inherent support in Hibernate.

So this is good if we want to create a sub class of a specific type for each row but what about if we want to create an instance of a specific class for a value of a column within that row. So in a way some type of component inheritance mapping. This is required if I really do not want to convert a value object (component) into an entity as that might mean sacrifice on the part of good model design as I am loosing the distinction between a component and an entity.

A workaround for the moment could be to somehow use a UserType to create instance of such objects based upon the value stored in the column. The concept of discriminator column can still help us. Let’s see how by taking up the following example

(more...)

Files in a distributed transaction

Posted by Meindert Deen around lunchtime:

At a client we are now using files and datasources together. We want the write actions to the database and the files to be in one transaction. We want this because the files represent the database data for legacy applications. As there is no distributed transaction API for files which is JTA (Java Transaction API) compatible we had to find a solution to implement this. This post describes the (big) steps we did and the solution we found. Of course, you can skip the steps and go straight to the solution. ;-)
(more...)

Next Page »