Array datatype contributor for Hibernate ORM 5.2
If you need to use PostgreSQL arrays in your JPA entities and already use Hibernate as your JPA provider, this is the plugin for you.
One intentional limitation is that you cannot use arrays of primitives. This is because java.sql.Connection.createArrayOf
requires an array of objects. While conversion is doable, it's undesirable.
Set-up for testing environment:
- PostgreSQL 9 server or newer, running on port 5432
- Username, password and database
hibernate_orm_test
with full privileges that database.
Compiling:
./gradlew clean build
If you want to build without running the tests, use assemble
instead of build
.
To make the final jar available for your Maven or compatible project type that uses the Maven repository, run:
./gradlew publishToMavenLocal
Now you just need to add the dependency to your project's pom.xml
.
<dependency>
<groupId>com.mopano</groupId>
<artifactId>hibernate-array-contributor</artifactId>
<version>1.2</version>
</dependency>
Or if you're using Gradle:
dependencies {
compile group: 'com.mopano', name: 'hibernate-array-contributor', version: '1.2'
}
Changelog:
version 1.2
- added
java.util.UUID
conversion using Postgres-specific type handler. - fixed
java.lang.Class
conversion. - fixed
java.time.Duration
conversion. - fixed
java.time.OffsetTime
conversion. hibernate.arrays.uuidtype
JPA configuration property can be set to override the default PostgresUUID array type handler.
version 1.1
- Miscelaneous internal changes.
Tested working types as of version 1.2:
java.lang.String[]
asvarchar[]
andtext[]
java.lang.Long[]
asbigint[]
java.lang.Integer[]
asinteger[]
java.lang.Short[]
assmallint[]
java.lang.Boolean[]
asboolean[]
java.lang.Float[]
asreal[]
java.lang.Double[]
asdouble precision[]
java.lang.Class[]
asvarchar[]
andtext[]
java.math.BigDecimal[]
asnumeric[]
java.math.BigInteger[]
asnumeric[]
java.net.URL[]
asvarchar[]
andtext[]
java.util.Currency[]
asvarchar[]
java.util.Locale[]
asvarchar[]
java.util.UUID[]
asuuid[]
java.time.Instant[]
astimestamptz[]
java.time.Duration[]
asbigint[]
java.time.LocalDate[]
asdate[]
java.time.LocalTime[]
astime[]
java.time.LocalDateTime[]
astimestamp[]
java.time.ZonedDateTime[]
astimestamptz[]
. Warning: Offset is not precisely preserved within the database itself. If you are not running the server and your java application in UTC, thenequals(Object other)
is false, butisEqual(ChronoZonedDateTime<?> other)
is true. It is fine with calculations, comparisons and conversions, if you are aware of this.java.time.OffsetDateTime[]
astimestamptz[]
. Warning: Offset is not precisely preserved within the database itself. If you are not running the server and your java application in UTC, thenequals(Object other)
is false, butisEqual(OffsetDateTime other)
is true. It is fine with calculations, comparisons and conversions, if you are aware of this.java.time.OffsetTime[]
astimetz[]
. Warning: Offset is not precisely preserved within the database itself. If you are not running the server and your java application in UTC, thenequals(Object other)
is false, butisEqual(OffsetTime other)
is true. It is fine with calculations, comparisons and conversions, if you are aware of this.org.w3c.dom.Document[]
asxml[]
(support not included in this package)javax.json.JsonStructure[]
asjsonb[]
(support not included in this package)
Types that don't work:
java.util.TimeZone
Data becomes mangled.java.sql.Date
Reflection type detection failure. Special case could be written, but type is deprecated. Just usejava.time.LocalDate
.java.sql.Time
Reflection type detection failure. Special case could be written, but type is deprecated. Just usejava.time.LocalTime
.java.sql.Timestamp
Reflection type detection failure. Special case could be written, but type is deprecated. Just usejava.time.Instant
.
Types that remain untested and likely don't work:
java.util.Calendar
. Use thejava.time.*
classes instead.java.util.Date
. Use thejava.time.*
classes instead.- Numeric boolean types.
- Yes/no boolean types.
- True/false textual boolean types.
- All binary types.
- All CLOB/BLOB types.
- Char array type. If you even try to use that instead of
varchar
ortext
you might be crazy. - National char/string/text types. The only major databases that support these don't support arrays at this time.
Known issues:
Hibernate 5.2.9.Final
introduced a regression where your arrays cannot contain null values. This is fixed in 5.2.14.Final
and 5.3.0.Final
.