0

I am using SpringBoot 3.5, PostgreSQL and Hibernate/JPA as ORM. While using JSONB column from DB I am having this error.

org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement [ERROR: column "column_name" is of type jsonb but expression is of type character varying

This is the mapping class.

@Entity
@Table(name="SCHEDULED_JOBS")
public class SchedulerJob extends AbstractModel implements Serializable{
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name="job_name", nullable=false)
    private String jobName;
    @Column(name="job_group", nullable=false)
    private String jobGroup;
    @Column(name="job_class", nullable=false)
    private String jobClass;
    @Column(name="cron_expression")
    private String cronExpression;
    @Column(name="repeat_time")
    private Long repeatTime;
    @Column(name="cron_job")
    private Boolean cronJob;
    @Column(name="chain_jobs")
    private String chainJobs;
    @Column(name="job_status")
    private String jobStatus;
    @Column(name = "job_data", columnDefinition = "jsonb")
    private Map<String, Object> jobDataMap;
}

Any help how can I resolve it?

Thanks, Atul

1 Answer 1

0

Fixed the issue.

Added

@JdbcTypeCode(SqlTypes.JSON)

To the job_data column which is jsonb.

@Entity
@Table(name="SCHEDULED_JOBS")
public class SchedulerJob extends AbstractModel implements Serializable{
    
    private static final long serialVersionUID = 7L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name="job_name", nullable=false)
    private String jobName;
    @Column(name="job_group", nullable=false)
    private String jobGroup;
    @Column(name="job_class", nullable=false)
    private String jobClass;
    @Column(name="cron_expression")
    private String cronExpression;
    @Column(name="repeat_time")
    private Long repeatTime;
    @Column(name="cron_job")
    private Boolean cronJob;
    @Column(name="chain_jobs")
    private String chainJobs;
    @Column(name="job_status")
    private String jobStatus;
    @Column(name = "job_data", columnDefinition = "jsonb")
    @JdbcTypeCode(SqlTypes.JSON)
    private Map<String, Object> jobDataMap;
}

Thanks,

Atul

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.