spring org.postgresql.util.PSQLException:错误:列必须出现在GROUP BY子句中或在集合函数中使用

lnlaulya  于 2022-11-21  发布在  Spring
关注(0)|答案(1)|浏览(244)

我有2个单向关联的实体。
第一个
以及三个表albums、album_cards和album_album_cards(用于Map)
将实体Map到模型时,会引发异常。
第一次
最后一个sql日志为

Hibernate: select album0_.id as id1_1_, album0_.is_public as is_publi2_1_, album0_.name as name3_1_, album0_.owner_id as owner_id4_1_ from albums album0_ where album0_.owner_id=? and album0_.id=?
Hibernate: select cards0_.album_id as album_id8_0_0_, cards0_.id as id1_0_0_, cards0_.id as id1_0_1_, cards0_.card_id as card_id2_0_1_, cards0_.condition as conditio3_0_1_, cards0_.count as count4_0_1_, cards0_.design as design5_0_1_, cards0_.price as price6_0_1_, cards0_.updated as updated7_0_1_ from album_cards cards0_ where cards0_.album_id=?

Map器代码:

51    protected List<AlbumPositionModel> albumCardListToAlbumPositionModelList(List<AlbumCard> list) {
52        if (list == null) {
53            return new ArrayList<>();
54        }
55
56        List<AlbumPositionModel> list1 = new ArrayList<>();
57        list.forEach(e -> list1.add(albumCardToAlbumPositionModel(e))); <---- exception throws there. And it throws if i call any method of list (List<AlbumCard>)
58        return list1;

调用Map器的服务方法(我尝试使用事务注解,没有事务注解,结果相同):

@Override
    public Optional<AlbumModel> getAlbum(String ownerId, Long albumId) {
        if (ownerId != null) {
            return albumRepo
                    .findByOwnerIdAndId(ownerId, albumId)
                    .map(mapper::toModel);
        } else {
            return albumRepo
                    .findByIdAndIsPublic(albumId, true)
                    .map(mapper::toModel);
        }
    }

有人能帮我吗?我做错了什么?

cxfofazt

cxfofazt1#

尝试将count列重命名为

private Integer count;

@Column(name = "CARD_COUNT")
private Integer count;

相关问题