Search code examples
hibernatejpajakarta-eehsqldbjboss-arquillian

JPA Entity CLOB column different data type for testing


I am persisting CLOB data using Hibernate and Hikari pool. While testing I am using HSQL in-memory DB. But production I am using other DB. CLOB's java data type is String for HSQL DB. but my real environment DB data type is byte[]. I am using Arquillian for testing.

How do I use byte[] data type for main coding and string data type for testing ?

I tried with Alternative, but it doesn't work and also I tried Specializes, no luck.

@Entity
class Article {
   @Id
   private long id;
    @Lob
    @Column(name="data", columnDefinition = "CLOB")
    private byte[] data;

}

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.3.7.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-hikaricp</artifactId>
            <version>5.3.7.Final</version>
        </dependency>

How to solve this data type issue while testing ?


Solution

  • Since my production and test Db are different and faced CLOB data type for Java is different in both DB.

    create.sql

    create table article (id integer,data binary(500));

    I created different schema for testing and loaded those schema via persistence.xml. I did below configuration in persistence.xml for testing alone.

        <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
        <property name="javax.persistence.schema-generation.create-source" value="script"/>
        <property name="javax.persistence.schema-generation.create-script-source" value="schema/create.sql"/>
        <property name="javax.persistence.schema-generation.drop-source" value="script"/>
        <property name="javax.persistence.schema-generation.drop-script-source" value="schema/drop.sql"/>
    

    All create table schema is available in create.sql and drop table schema is available in drop.sql.

    Working good now.