如何解决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 举报,一经查实,本站将立刻删除。