gpt4 book ai didi

java - Spring 数据 2.1.1 org.hibernate.HibernateException : Got different size of tuples and aliases?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:07 26 4
gpt4 key购买 nike

从Spring Boot的1.5.4升级到2.1.0 LTS之后

我遇到了一些关于特定存储库方法的问题。

我检查了 SO 和 JIRA 上提及 @Query@ResultsSetMapping 的各种问题,并相应地应用了这些更改,但我仍然面临同样的问题。

例如这里:

存储库

@CrossOrigin
@RepositoryRestResource(path = "/iCreateChange")
public interface ICreateChangeRepository extends JpaRepository<ICreateChange, Long> {

List<ChangeTask> listStartedChangesByInitiator(
@Param("initiator")
@RequestParam
@ApiParam(name = "initiator", value = "initiator")
String initiator);

List<ChangeTask> listDataValuesAndStatusByChangeId(
@Param("changeId")
@RequestParam
@ApiParam(name = "changeId", value = "changeId")
Long changeId);
}

实体

@SqlResultSetMappings({
@SqlResultSetMapping(
name = "StartedChangeMapping",
classes = @ConstructorResult(
targetClass = ChangeTask.class,
columns = {
@ColumnResult(name = "id", type = Long.class),
@ColumnResult(name = "status", type = String.class),
@ColumnResult(name = "data_values", type = String.class)
}
)
),
@SqlResultSetMapping(
name = "ActiveTaskChangeMapping",
classes = @ConstructorResult(
targetClass = ChangeTask.class,
columns = {
@ColumnResult(name = "id", type = Long.class),
@ColumnResult(name = "status", type = String.class),
@ColumnResult(name = "data_values", type = String.class)
}
)
)
})
@NamedNativeQueries({
@NamedNativeQuery(
name = "ICreateChange.listStartedChangesByInitiator",
query =
"SELECT id as id, status as status, data_values as data_values "
+ "FROM icreate_change "
+ "WHERE initiator = :initiator "
+ "AND workflow_process_id = 0",
resultSetMapping = "StartedChangeMapping"
),
@NamedNativeQuery(
name = "ICreateChange.listDataValuesAndStatusByChangeId",
query =
"SELECT id as id, status as status, data_values as data_values "
+ "FROM icreate_change "
+ "WHERE id = :changeId",
resultSetMapping = "ActiveTaskChangeMapping"
)

})

@Data
@Entity
@Table(name = "icreate_change")
public class ICreateChange {

public ICreateChange() {}
....

我错过了什么吗?

堆栈跟踪

org.hibernate.HibernateException: Got different size of tuples and aliases
at org.hibernate.jpa.spi.NativeQueryTupleTransformer$NativeTupleImpl.<init>(NativeQueryTupleTransformer.java:68) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.jpa.spi.NativeQueryTupleTransformer.transformTuple(NativeQueryTupleTransformer.java:28) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.hql.internal.HolderInstantiator.instantiate(HolderInstantiator.java:85) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.loader.custom.CustomLoader.getResultList(CustomLoader.java:433) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.loader.Loader.list(Loader.java:2501) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2223) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1053) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:170) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.query.Query.getResultList(Query.java:135) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]

调试

调试 NativeTupleImpl 的实现显示别名和元组在那里,但是存在嵌套问题。有一个包含所有值的元组对象,但有 3 个别名,它们没有嵌套并且作为三个实体。这是造成不匹配的原因

enter image description here

引用:

https://jira.spring.io/si/jira.issueviews:issue-html/DATAJPA-1280/DATAJPA-1280.html

"Got different size of tuples and aliases" exception after Spring Boot 2.0.0.RELEASE migration

最佳答案

问题与 Hibernate 默认情况下如何将其元组实体映射到对象或对象列表有关。

在这种情况下,它期望三个元组映射到 POJO 中的各个列。

这是让它工作的代码(注意省略了@ConstructorResult)

@SqlResultSetMapping(
name = "TaskChangeMapping",
columns = {
@ColumnResult(name = "id", type = Long.class),
@ColumnResult(name = "status", type = String.class),
@ColumnResult(name = "data_values", type = String.class)

})

关于java - Spring 数据 2.1.1 org.hibernate.HibernateException : Got different size of tuples and aliases?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53169393/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com