Reputation: 149
I have an application that contains some JPA classes that are using LocalDate / LocalDateTime fields and these fields are being mapped into PostgreSQL columns as Bytea.
The greatest problem with this approach is that I can't do queries with SQL, for example, I can't query this: SELECT * FROM star_date BETWEEN '2020-01-01' AND '2020-01-02', because DateTime and date columns using the Bytea type.
Below a have an example of a class that shows my current problem scenery! This class is using JPA to generate the table in PostgreSQL, so it happens automatically. Look at created fiend into class and design of the table.
@Data
@Entity
@Table(name = "processes")
public class Process implements Serializable {
@Id
@GeneratedValue(generator = "ProcessSequenceGenerator")
private Long id;
private Long legacyId;
private String createdBy;
private LocalDateTime created;
}
Has somebody ever had an issue like this one?
Upvotes: 1
Views: 2844
Reputation: 149
I'm using Spring Boot 1.4.7.RELEASE! So a fix my problem including into Column the property columnDefinition and a @Convert like below:
@Column(nullable = false, updatable = false, columnDefinition = "TIMESTAMP")
@Convert(converter = LocalDateTimeConverter.class)
private LocalDateTime created;
Right now, I'm looking for a way to convert bytea that is into my current table in postgresql.
Upvotes: 2