我正在尝试使用 JPA 从表中选择 jsonb 数据类型的列,但我在实现这一点时遇到问题,但我可以选择不属于 jsonb 数据类型的其他列。
这里是实体类的内容
@EqualsAndHashCode(callSuper = true)
@Data
@Entity(name = "Assessment")
@Table(name = "assessment")
@TypeDefs({
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
@AllArgsConstructor
@NoArgsConstructor
public class Assessment extends ModelWithUUID {
@Column(name = "session_id")
private Integer sessionId;
@Column(name = "section_id")
private Integer sectionId;
@Column(name = "subject_id")
private Integer subjectId;
@Column(name = "assessment", columnDefinition = "jsonb")
@Type(type = "jsonb")
private List assessment;
}
这是我的存储库
@Repository
public interface AssessmentRepository extends
JpaRepository<Assessment, UUID> {
@Query(value = "select assessment from
assessment where subject_id = 8 ", nativeQuery = true)
List<Object> findAssessmentsBySubjectId();
}
我的 Controller 看起来像这样
ResponseBody
@GetMapping("/subject/assessment")
public List<Object> getAssessment(){
return assessmentRepository.findAssessmentsBySubjectId();
}
这是我遇到的错误
"timestamp": "2019-08-22T10:25:08.507+0000",
"status": 500,
"error": "Internal Server Error",
"message": "No Dialect mapping for JDBC type: 1111; nested exception
is org.hibernate.MappingException: No Dialect mapping for JDBC type:
1111",
"trace": "org.springframework.orm.jpa.JpaSystemException: No Dialect
mapping for JDBC type: 1111; nested exception is
org.hibernate.MappingException: No Dialect mapping for JDBC type:
1111\n\tat
最佳答案
例如,您还可以定义用于 jsonb 反序列化的类
@Column(name = "assessment")
@Type(type = "jsonb")
private Assessment assessment;
关于java - 如何使用 jpa (hibernate) 从表中仅选择 postgres jsonb 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57607330/