gpt4 book ai didi

java - org.hibernate.criterion.Order 无法解析字符串的 '.' 属性

转载 作者:行者123 更新时间:2023-12-01 09:14:45 24 4
gpt4 key购买 nike

我尝试使用 Hiberante criteria API 对结果进行升序或降序排序。

我定义了 A 类; (简化格式)

@Entity
public class A {

@ManyToOne
@JoinColumn(name = "yy")
B b;

...
}

我的 B 实体就像;

@Entity
public class B extends C {
...
}

@Entity
public class C {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id", updatable = false, nullable = false)
private Long id;

@NotNull
@NotEmpty
@Size(max = 64)
@Pattern(regexp = REGEX_CODE, message = "Must be valid LOB Code")
@Column(name = "code", updatable = false, nullable = false)
private String code;


}
}

当我使用;

criteria.addOrder(Order.asc(b.id));  //works

criteria.addOrder(Order.asc(b.code)); //Throws error

Error


Caused by: org.hibernate.QueryException: could not resolve property: manufacturer.code of: xx.core.model.wetstock.ATG
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:62)
at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:77)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1793)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:510)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:469)
at org.hibernate.criterion.Order.toSqlString(Order.java:109)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getOrderBy(CriteriaQueryTranslator.java:414)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:106)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:75)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:80)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1841)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:365)
at com.cdi.crud.infra.Crud.list(Crud.java:450)
at com.cdi.crud.infra.CrudService.paginate(CrudService.java:210)

当我看到 B 的表时,我看到“id”列在那里。没有显示其他列。其他列在表“C”下创建。

所以如果我使用“.”要对表 C 中显示的列进行排序,我得到属性无法解决问题。

我该如何克服这个问题?

最佳答案

我通过添加“别名”来修复。

eg: criteria.createAlias("b" ,"bob").addOrder(Order.asc(bob.code))

关于java - org.hibernate.criterion.Order 无法解析字符串的 '.' 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40644563/

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