How to map tsrange type in Hibernate

This is a sample class (Entity class) that maps the "tsrange type" of PostgreSQL in Hibernate. There were few articles about the mapping method of "tsrange type", so I wrote it.

SampleEntity.java


package xxx;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.vladmihalcea.hibernate.type.range.PostgreSQLRangeType;
import com.vladmihalcea.hibernate.type.range.Range;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "xxx_table")
@TypeDefs({
    @TypeDef(
        name = "jsonb",
        typeClass = JsonBinaryType.class
    ),
    @TypeDef(
        typeClass = PostgreSQLRangeType.class,
        defaultForType = Range.class
    )
])
@XmlRootElement
@Data
@NoArgsConstructor
@NamedQueries([
    @NamedQuery(name = "SampleEntity.findById", query = "SELECT s FROM SampleEntity s WHERE s.id = :id")})
public class SampleEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "id")
    private Integer id;

    @Column(name = "tsrange_col", columnDefinition = "tsrange")
    private Range<Date> tsrangeCol;
}


Recommended Posts

How to map tsrange type in Hibernate
How to use Map
How to use map
How to use Map
How to type backslash \
[Java] How to use Map
[Java] How to use Map
How to use Java Map
How to use Lombok in Spring
How to find May'n in XPath
How to hide scrollbars in WebView
How to run JUnit in Eclipse
How to iterate infinitely in Ruby
[Rails] How to write in Japanese
How to run Ant in Gradle
How to master programming in 3 months
How to learn JAVA in 7 days
How to get parameters in Spark
How to install Bootstrap in Ruby
How to use InjectorHolder in OpenAM
How to introduce jQuery in Rails 6
How to use classes in Java?
How to name variables in Java
How to set Lombok in Eclipse
How to use Java enum type
How to concatenate strings in java
How to install Swiper in Rails
How to increment the value of Map in one line in Java
[swift5] How to specify color in hexadecimal
How to implement search functionality in Rails
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
How to change app name in rails
How to get date data in Ruby
How to use custom helpers in rails
How to reflect seeds.rb in production environment
How to use named volume in docker-compose.yml
How to insert a video in Rails
How to standardize header footer in Thymeleaf
How to include Spring Tool in Eclipse 4.6.3?
[Rails] How to use the map method
How to add jar file in ScalaIDE
How to do base conversion in Java
[Swift] How to fix Label in UIPickerView
How to have params in link_to method
How to use Docker in VSCode DevContainer
How to fix system date in JUnit
How to implement coding conventions in Java
How to embed Janus Graph in Java
[rails] How to configure routing in resources
How to get the date in java
How to implement ranking functionality in Rails
How to use environment variables in RubyOnRails
How to implement asynchronous processing in Outsystems
How to publish a library in jCenter
How to specify id attribute in JSF
Understand in 5 minutes !! How to use Docker
How to overwrite Firebase data in Swift
How to use credentials.yml.enc introduced in Rails 5.2
How to assemble JSON directly in Jackson