Hibernate and Firebird – Support for Temporary Tables

by Philip Barlow / from beautifuldecay.com

I had problems to use Hibernate(JPA) to work with Firebird a while ago. Every connection opened was not being closed, I couldn’t ever think to use a pool of connection in my web service and the temporary tables was being created next to other tables. In this post, I will focus on the problem with temporary tables.

Hibernate creates temporary tables in other databases too but there is a specifically problem with Firebird. After sometime (after a lot of websites), I figured out that the Hibernate dialect for Firebird doesn’t know about global temporary tables, so it creates them as normal tables instead.

So, the solution for this problem is implement a class that will deal with the Dialect and in this class take control the creation of the temporary tables.

public class Firebird21Dialect extends FirebirdDialect {
public boolean dropTemporaryTableAfterUse() {
return true;
public String getCreateTemporaryTablePostfix() {
public String getCreateTemporaryTableString() {
public boolean supportsTemporaryTables() {
return true;

In the persistence.xml add this attribute that references our new class:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="MyPersistenceUnit">
<property name="hibernate.dialect" value="br.com.tassioauad.myapp.resource.Firebird21Dialect" />

view raw


hosted with ❤ by GitHub

2 comentários em “Hibernate and Firebird – Support for Temporary Tables

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s