我在PostgreSQL
中有一个表,其字段类型为JSONB
,实体如下所示:
@Entity
@Table(name = "test_table")
@TypeDef(name = "jsonb", typeClass = JsonBinaryType::class)
class TestEntity(
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "test_id")
var main: Main? = null,
@Column(name = "id")
val id: String,
@Column(name = "fallback_id")
var fallbackId: String? = null,
@Column(name = "properties", columnDefinition = "jsonb")
@Type(type = "jsonb")
val properties: MutableMap<String, Any> = mutableMapOf(),
字符串projection
是这样的:
interface TestProjection {
val id: String
val fallbackId: String
val properties: MutableMap<String, Any>
}
型
我想从数据库中检索并Map到这个projection
(使用JSONB
字段作为Map),但是当我尝试使用这个repository
这样做时:
@Repository
interface TestRepository : JpaRepository<TestEntity, UUID> {
fun findByFallbackIdIn(fallbackIds: Set<String>): Set<TestEntity>
@Query(
nativeQuery = true,
value = """
SELECT
cast(t.id as varchar) as id,
cast(t.fallback_id as varchar) as fallback_id,
t.properties as properties,
FROM test_table t
AND t.id < :last_uuid
ORDER by t.id DESC
LIMIT :batch_size
"""
)
fun findTestForSomeLogic(
@Param("last_uuid") lastUuid: UUID,
@Param("batch_size") batchSize: Int,
): List<TestProjection>
}
型
我从hibernate得到了一个异常:
No Dialect mapping for JDBC type: 1111; nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
型
那么如何将JSONB
Map到投影的字段?
1条答案
按热度按时间cbwuti441#
如何德米特里波波夫建议我附上文章的一部分,可以帮助你,问题是在方言的一部分,你可以扩展你目前的方言在文章
的数据
需要提供自定义的hibernate方言:
的
文章:hibernate-no-dialect-mapping-for-jdbc-type