I have following entity :
<code>import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.Instant;
import java.util.Objects;
@Entity
@Table(name = "my_example")
@IdClass(MyExampleId.class)
public class MyExample implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@OneToOne
@NotNull
@JoinColumn(name = "entity1_id", referencedColumnName = "id")
private Entity1 entity1;
@Id
@OneToOne
@JsonIncludeProperties(value = {"id"})
@NotNull
@JoinColumn(name = "entity2_id", referencedColumnName = "id")
private Entity2 entity2;
@NotNull
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private MyStatusEnum status;
@Size(max = 5000)
@Column(name = "error_msg", length = 5000)
private String errorMsg;
@NotNull
@Column(name = "created_date", nullable = false, updatable = false)
private Instant createdDate = Instant.now();
... + empty constructor + getters and setters + toString()
</code>
<code>import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.Instant;
import java.util.Objects;
@Entity
@Table(name = "my_example")
@IdClass(MyExampleId.class)
public class MyExample implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@OneToOne
@NotNull
@JoinColumn(name = "entity1_id", referencedColumnName = "id")
private Entity1 entity1;
@Id
@OneToOne
@JsonIncludeProperties(value = {"id"})
@NotNull
@JoinColumn(name = "entity2_id", referencedColumnName = "id")
private Entity2 entity2;
@NotNull
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private MyStatusEnum status;
@Size(max = 5000)
@Column(name = "error_msg", length = 5000)
private String errorMsg;
@NotNull
@Column(name = "created_date", nullable = false, updatable = false)
private Instant createdDate = Instant.now();
... + empty constructor + getters and setters + toString()
</code>
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.Instant;
import java.util.Objects;
@Entity
@Table(name = "my_example")
@IdClass(MyExampleId.class)
public class MyExample implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@OneToOne
@NotNull
@JoinColumn(name = "entity1_id", referencedColumnName = "id")
private Entity1 entity1;
@Id
@OneToOne
@JsonIncludeProperties(value = {"id"})
@NotNull
@JoinColumn(name = "entity2_id", referencedColumnName = "id")
private Entity2 entity2;
@NotNull
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private MyStatusEnum status;
@Size(max = 5000)
@Column(name = "error_msg", length = 5000)
private String errorMsg;
@NotNull
@Column(name = "created_date", nullable = false, updatable = false)
private Instant createdDate = Instant.now();
... + empty constructor + getters and setters + toString()
Type of db is postgresql. It is a very strange problem, when error_msg is null in db entire entity is returned as null. When I assign an empty String or any String everything works fine. What could be the problem? I’ve tried changing the type, give it a smaller size but it doesnt help. Java version 17, SpringBoot version 2.5.4, hibernate version 5.4.32.