1. 2015-08-07 - Analysing JPA DDL Generation in Hibernate; Tags: Analysing JPA DDL Generation in Hibernate

    Analysing JPA DDL Generation in Hibernate

    Using the JPA (Java Persistence API) 2.0 with Hibernate for a database integration test against a in-memory db like H2 or HSQLDB, is a good way to test the JPA ORM (object relational mapping). In the process, errors might occur depending on the database vendor. Following example illustrate a problem with Hibernate and HSQLDB.

    The output is truncated.

    13:50:55.262 [main] DEBUG org.hibernate.SQL - insert into BLACKLIST (MANDANT,..,BLOCKEDID) values (?,..,?)
    13:50:55.263 [main] WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 3403, SQLState: 22003
    13:50:55.263 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - data exception: numeric value out of range;  table: BLACKLIST column: ID
    13:50:55.272 [main] WARN  Transaction - Unexpected exception from beforeCompletion; transaction will roll back

    The entity

    public class Blacklist {
        @Column(nullable = false)
        private BigInteger blockedId;

    The value of used id

    BigInteger id = BigInteger.valueOf(6710203000580400250L);

    Numeric value out of range seems not to be true. H2 maps BigInteger to BigInt, so HSQLDB should behave the same way?

    Activate SQL debug in logging configuration (+logback-test.xml+).

    <logger name="org.hibernate.SQL" level="DEBUG"/>

    The trace:

    13:50:49.228 [main] DEBUG org.hibernate.SQL - create table BLACKLIST (id bigint not null, BLOCKEDID numeric(19,2) not null, .., primary key (id))

    Obviously Hibernate does not take BigInt for HSQLDB, and tries to use 19 digits with 2 decimal places. By changing the mapping, we enforce a correct mapping.

    public class Blacklist {
        @Column(nullable = false, precision = 38, scale = 0)
        private BigInteger blockedId;
    14:02:26.744 [main] DEBUG org.hibernate.SQL - create table BLACKLIST (id bigint not null, BLOCKEDID numeric(38,0) not null, .., primary key (id))

    Now the value will fit into the column.

  2. 2015-07-06 - Add HyperSQL module to JBoss; Tags: Add HyperSQL module to JBoss

    Add HyperSQL module to JBoss

    This post explains how to create a hsqldb module for JBoss EAP.

    Admin CLI

    This CLI instruction will copy the JDBC jar into the created module folder. As dependencies the Java EE APIs are referenced.

    module add --name=org.hsqldb.jdbcDriver \
     --resources=C:\Daten\lib\hsqldb.jar \

    Manual installation

    Create the following module for HSQLDB under JBOSS_HOME/modules


    Contents of module.xml

    <module xmlns="urn:jboss:module:1.0" name="org.hsqldb">
        <resource-root path="hsqldb.jar"/>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>

    Copy the hsqldb.jar in the folder main. Configuration: Add in standalone.xml following datasource

    <datasource jndi-name="java:/testHSQLMem" pool-name="testHSQLMem"
     enabled="true" use-java-context="true">
     <driver name="hsqldb" module="org.hsqldb">