我试图对具有@Collection注释的属性进行投影,但在提取结果集时总是失败。但是,对于简单的列,它不会出现任何问题:
这是班级
@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "table")
public class Table implements Serializable {
@Id
@Column(length = 10)
private String name;
@Column(name = "series")
private String series;
@Fetch(FetchMode.SUBSELECT)
@BatchSize(size = 50)
@ElementCollection
@CollectionTable(
name = "table_word",
joinColumns = @JoinColumn(name = "name")
)
@Column(name = "value")
private List<String> tWord;
}
然后我有一个投影类:
@RegisterForReflection
@Setter
@Getter
@Builder
@AllArgsConstructor
public class TableAttribute<T> {
private T t;
}
在PanacheRepository类中,它使用的是类似系列的简单元素,但不是tWord:
public class TableRepository implements PanacheRepository<Table> {
...
find(
"select v.series from " + Table.class.getName() + " v"
.project(TableAttribute.class)
.page(Page.ofSize(limit))
.list(); // works
find(
"select v.tWord from " + Table.class.getName() + " v"
.project(TableAttribute.class)
.page(Page.ofSize(limit))
.list(); // does not work
}
这就是我得到的错误:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
...
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "."
...
知道吗?
---编辑。
启用SQL日志记录后,以下是查询:
// with the series:
Hibernate:
select
table0_.series as col_0_0_
from
fss.table vehicle0_
// with the tWord:
Hibernate:
select
. as col_0_0_
from
fss.table table0_
inner join
fss.table_word tword1_
on table0_.name=sas1_.name