Home > front end >  Compatible type of bytearray for Postgres, MySQL, HSQL
Compatible type of bytearray for Postgres, MySQL, HSQL

Time:01-07

I have a column which looks like this:

@Column(name = "somedata", columnDefinition = "bytea")
@Size(min = 1, max = 65535)
private byte[] somedata;

This bytea column definition works fine with PostgreSQL, but for testing purposes I use HSQL which is not supporting it, only if I rename it to blob. I want to use MySQL for a second datasource and that is also not supporting the mentioned HSQL datatype.

So my question is that is there an universal solution for byte array type that can work for both three of datasources?

CodePudding user response:

I've managed to get it work for both three of databases in this way:

Now the types are:

  1. HSQL-blob
  2. PostgreSQL-bytea
  3. MySQL-mediumblob
@Column(name = "somedata", length = 5 * 1024 * 1024)
@Size(min = 1, max = 65535)
@Type(type="org.hibernate.type.BinaryType")
@Lob
private byte[] somedata;
  •  Tags:  
  • Related