-
Recent Posts
Recent Comments
- sherif sadek on Understanding Hibernate session flushing
- Koushik Paul on Hibernate query limitations and correlated sub queries
- Joseph Albert on Showing unused TestNG tests
- Iván on Maven offline build fails to resolve artifacts in your local repository
- Peter on Comparing two MySQL databases
Archives
- October 2024
- July 2024
- June 2024
- May 2024
- January 2024
- October 2023
- July 2023
- January 2023
- July 2022
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- December 2020
- June 2020
- May 2020
- January 2019
- November 2018
- September 2017
- June 2017
- September 2016
- August 2016
- February 2016
- July 2015
- November 2014
- October 2014
- August 2014
- April 2014
- February 2014
- December 2013
- November 2013
- May 2013
- February 2013
- January 2013
- October 2012
- September 2012
- July 2012
- April 2012
- February 2012
- January 2012
- November 2011
- October 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- November 2010
- October 2010
Categories
Meta
Category Archives: Hibernate
Hibernate Best Practices – using sequences for bulk inserts
For many database tables, an auto increment column is used for the primary key. This is fine for inserting single values, but if you want to bulk insert hundreds or thousands of values and you need to refer to the … Continue reading
Hibernate Best Practices – Parameterising Criteria Queries
Recently one of our database team pointed out some queries that were not running efficiently. We looked into the queries and they were Hibernate criteria queries. Consider a simple helper method that is creating a predicate for use in a … Continue reading
Hibernate internals – how does pagination work?
Hibernate supports pagination for all query types – HQL, Criteria and SQL, via the query setMaxResults() and setFirstResult() methods, but how does this work under the covers? Well, assuming your database supports it, it will add a row_number() to your … Continue reading
Optimistic locking and versioning with Hibernate
Just put a small example of Hibernate optimistic locking and versioning on github: https://github.com/hedleyproctor/HibernateVersioningExample Hibernate uses an optimistic locking strategy, based on versioning. This means it tries to avoid taking a lock on data and instead relies on having a … Continue reading
Distinct, order by and Hibernate HQL
Recently someone posted a question on stackoverflow explaining that they were having a problem with a Hibernate HQL query that involved both order by and a distinct in the select. The query was across five linked entities – a many … Continue reading
Understanding the Hibernate session cache
When you use Hibernate, you do so via a session. It is well known that the session acts as a first level cache, but sometimes this can cause confusing behaviour. Let’s look at a simple example. Suppose I have Customer … Continue reading
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
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
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
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