You could use the @Lob
annotation on your field which will yield type longtext
on MySQL and type text
on PostgreSQL:
package models;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
@Entity
public class Foo {
@Id
public Long id;
@Lob
public String bar;
}
in MySQL this yields:
mysql> describe foo;
+-------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| bar | longtext | YES | | NULL | |
+-------+------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
in PostgreSQL this yields:
foodb=> \d foo;
Table "public.foo"
Column | Type | Modifiers
--------+--------+-----------
id | bigint | not null
bar | text |
Indexes:
"pk_foo" PRIMARY KEY, btree (id)
According to the Java EE api:
The Lob type is inferred from the type of the persistent field or property
Which means that a field of type String
should give you some text blob and a field of type byte[]
should give you some binary blob.