JPA 查询 Postgressql 问题

问题描述

我在 CrudRepository 中定义了以下查询

interface RoundRepository : CrudRepository<Round,Long> {
     fun findByGameId(id: Long): Round?
     @Query("select r from Round r where r.game.id like ?1 order by r.createdAt desc")
     fun findLastByGameId(id: Long) : List<Round>
}

游戏和回合实体定义如下:

@Entity
class Game(
    @ManyToOne(optional = false)
    @JoinColumn(name = "firstplayer_id",referencedColumnName = "id")
    var firstPlayer: User,@ManyToOne(optional = false)
    @JoinColumn(name = "secondeplayer_id",referencedColumnName = "id")
    var secondplayer: User,@Size(min = 6,max = 60)
    var gameName: String,@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    var id: Long = 0,@DateTimeFormat
    val createdAt: Date = Date.from(Instant.Now())
) {
@OnetoMany(mappedBy = "game")
lateinit var rounds: Collection<Round>
}


@Entity
@Table(name = "round")
class Round(
    @ManyToOne
    @JoinColumn(name="game_id",referencedColumnName = "id")
    var game: Game,var cancelled: Boolean = false,var ended: Boolean = false,var winner: Winner = Winner.FirsT_PLAYER,var stateFirstPlayer: Int = -1,var stateSecondplayer: Int = -1,var moveIndexFirstPlayer: Int = -1,var moveIndexSecondplayer: Int = -1,@DateTimeFormat
    val createdAt: Date = Date.from(Instant.Now())
) {

@Transient
lateinit var firstPlayerMoves: Collection<Move>

@Transient
lateinit var secondplayerMoves: Collection<Move>

@Transient
lateinit var firstPlayerPositions: PlanesPositions

@Transient
lateinit var secondplayerPositions: PlanesPositions
}

调用方法如下:

var game: Game? = gamesRepository.findByGameName(gameName)
            ?: throw GameDoesNotExistException("A game with this name does not exist");
var rounds = roundRepository.findLastByGameId(game?.id!!)

我收到一个异常:org.hibernate.exception.sqlGrammarException:无法提取 ResultSet Postgres 的内部异常说: org.postgresql.util.PsqlException: ERROR: operator does not exist: bigint ~~ bigint

最初在圆桌会议中有字段 game_id 而不是非空规范。所以我认为这就是问题所在。现在我解决了这个问题,但我仍然收到同样的错误。 有人可以帮忙吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)