Author Archives: hedleyproctor

Understanding Hibernate session flushing

When you interact with Hibernate, you do so via a Hibernate session. Hibernate sessions are flushed to the database in three situations: When you commit a (Hibernate) transaction. Before you run a query. When you call session.flush(). However, it is … Continue reading

Posted in Hibernate | Tagged | 1 Comment

Hibernate query limitations and correlated sub queries

It’s well known that one of the key limitations of writing queries in Hibernate, using either HQL or criteria, is that you cannot write queries that have a join in the from clause. What is less well known is that … Continue reading

Posted in Hibernate | Tagged | Leave a comment

Bespoke join conditions with Hibernate JoinFormula

Recently someone posted a question on stackoverflow asking how to deal with a database join, where the foreign key could reside in one of two different columns. This situation is sometimes found in a legacy database schema, where someone has … Continue reading

Posted in Hibernate | Tagged | Leave a comment

Hibernate example 4 – many to many associations

I’ve put some code on Github that shows three ways of modelling many to many associations with JPA / Hibernate: Using a join table that is not mapped as either an entity or an embedded component type. Mapping the join … Continue reading

Posted in Hibernate, Java | Tagged , | Leave a comment

Hibernate example 3 – one to one associations

Just put a Hibernate example of the three different ways to create one-to-one associations on github: https://github.com/hedleyproctor/hibernate-one-to-one It contains a Customer entity, which has one-to-one associations to a UserProfile, MarketingPreferences and a Wistlist. Foreign key relationship. Customer has a foreign … Continue reading

Posted in Hibernate, Java | Tagged , | Leave a comment

Hibernate example 2 – one-to-many associations

Just put an example of how to use one-to-many associations with Hibernate on Github: https://github.com/hedleyproctor/hibernate-one-to-many Shows two examples of a one-to-many relationship between entities: Unordered one-to-many between Customer and Address. Ordered one-to-many between Customer and PaymentCard. The unordered association uses … Continue reading

Posted in Hibernate, Java | Tagged , | Leave a comment

Hibernate example 1 – inheritance and polymorphism

Have just put an example on Github of how to handle inheritance and polymorphism with Hibernate: https://github.com/hedleyproctor/hibernate-polymorphism It demonstrates the four ways of dealing with inheritance and polymorphism: Implicit polymorphism – no explicit mapping of the inheritance, but Hibernate can … Continue reading

Posted in Hibernate, Java | Tagged , | Leave a comment

Using database transactions with Apache Camel

Just put an example of using database transactions with Apache Camel on github: https://github.com/hedleyproctor/camel-transaction-example It is based on the example given at the start of Chapter 12 of “Camel In Action”, but using database transactions, rather than a JMS transaction. … Continue reading

Posted in Camel, Databases and SQL | Tagged , | Leave a comment

Testing Camel routes with Spring OSGi properties

If you are writing Camel routes using Spring to deploy to ServiceMix, you can’t use regular Spring properties, since ServiceMix is an OSGi container. Instead, you have to use OSGi properties. But if you try to start up your Spring … Continue reading

Posted in Camel, Java, Spring | Tagged , | 2 Comments

Practical Scala – processing XML

This is the second article in my series Practical Scala. The first article covered the basics of Scala syntax and then moved on to file IO and regular expressions. This article will show you how to read and write XML. … Continue reading

Posted in Scala | Tagged | Leave a comment