Skip to content

Extensions for QueryDSL APT to map entity properties mapped with Hibernate-Types.

Notifications You must be signed in to change notification settings

jwgmeligmeyling/hibernate-types-querydsl-apt

Repository files navigation

Hibernate-Types extensions for QueryDSL APT

Extensions for QueryDSL APT to map entity properties mapped with Hibernate-Types. Hibernate-Types makes fills in the gap between the Java Persistence API and modern Java ecosystems. It adds various custom types for mapping arrays and Java 8 Years and Months to Hibernate. It also adds various custom types for database specific data types, such as JSON, HStore and Range fields. However, after finding Hibernate-Types, it can be difficult to use these types in Querydsl queries. This extension for Querydsl makes sure that the query types are generated with the proper expression and path types, and that commonly used functions are made easily accessible.

What is currently supported?

  • PostgreSQL Ranges through Guava's Range class
  • Various arrays mapped as their native database equivalent
  • Various json/jsonb fields
  • hstore fields
  • Java Period and Duration objects for PostgreSQL intervals.

Future considerations are:

  • Release to Maven central

Example use

For example the mapping:

@Entity
@TypeDef(name = "range", typeClass = PostgreSQLRangeType.class, defaultForType = Range.class)
public class RangeEntity {

    @Id
    Long id;

    @Type(type = "range")
    Range<LocalDateTime> localDateTimeRange;

}

Allows for the following path creation:

QRangeEntity.rangeEntity.localDateTimeRange.intersects(Range.closedOpen(LocalDateTime.MIN, LocalDateTime.MAX))

For more examples, look at the following test cases:

Maven configuration

Note: this configuration is for Querydsl 5.0 and above. For earlier versions of Querydsl, use hibernate-types-querydsl-apt:1.1.0 instead.

<dependencies>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>${querydsl.version}</version>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>${querydsl.version}</version>
        <classifier>jpa</classifier>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>querydsl-ext-api</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>querydsl-ext-impl</artifactId>
        <version>${project.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>querydsl-ext-apt</artifactId>
        <version>${project.version}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

About

Extensions for QueryDSL APT to map entity properties mapped with Hibernate-Types.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Languages