spring 中的休眠查询使用 H2 启动:类型 "BOOLEAN" 和 "INTEGER" 的值不可比较
hibernate query in spring boot with H2: Values of types "BOOLEAN" and "INTEGER" are not comparable
我正在尝试 运行 自定义查询,但遇到了一个奇怪的(看似无关的)错误。
我得到的错误是:
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 90110, SQLState: 90110
Values of types "BOOLEAN" and "INTEGER" are not comparable; SQL statement:
select episode0_.episode_id as episode_1_1_, episode0_.air_date as air_date2_1_, episode0_.episode_number as episode_3_1_, episode0_.name as name4_1_, episode0_.season as season5_1_, episode0_.show_id as show_id7_1_, episode0_.watched as watched6_1_ from episode episode0_ where episode0_.episode_number=(select min(episode1_.episode_number) from episode episode1_ where episode1_.watched=0) and episode0_.season=(select min(episode2_.season) from episode episode2_ where episode2_.watched=0) and episode0_.show_id=? [90110-210]
我尝试过的事情:本机查询,以及这个:
我的存储库:
import model.Episode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Optional;
public interface EpisodeRepository extends JpaRepository<Episode, Long> {
Optional<Episode> findByEpisodeId(Long episodeId);
@Query("from EPISODE where episodeNumber = (SELECT MIN(episodeNumber) FROM EPISODE WHERE watched is false)" +
" AND season = (SELECT MIN(season) FROM EPISODE WHERE watched is false) " +
" AND show.showId = :showId")
Optional<Episode> findNextUnwatchedEpisode(@Param("showId") Long showId);
}
我的实体:
package model;
import lombok.*;
import javax.persistence.*;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
@Entity(name = "EPISODE")
public class Episode {
@Id
@Column(name = "EPISODE_ID", nullable = false)
private Long episodeId;
@Column(name = "NAME", nullable = false)
private String name;
@Column(name = "SEASON", nullable = false)
private Integer season;
@Column(name = "EPISODE_NUMBER", nullable = false)
private Integer episodeNumber;
@Column(name = "AIR_DATE", nullable = false)
private Date airDate;
@Column(name = "WATCHED", nullable = false)
private boolean watched;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="SHOW_ID")
private TVShow show;
}
application.properties:
spring.datasource.url=jdbc:h2:mem:my_tv;DB_CLOSE_ON_EXIT=FALSE;MODE=Oracle;
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
Hibernate ORM 仅从 5.6.5.Final 版本开始支持 H2 2.x.y。旧版本产生无效的 SQL,新版本的 H2 在默认配置中不接受。
您需要检查您的应用程序使用的 hibernate-core
jar 版本并将其更新到某个最新版本(当前版本是 5.6。7.Final)。
我正在尝试 运行 自定义查询,但遇到了一个奇怪的(看似无关的)错误。
我得到的错误是:
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 90110, SQLState: 90110
Values of types "BOOLEAN" and "INTEGER" are not comparable; SQL statement:
select episode0_.episode_id as episode_1_1_, episode0_.air_date as air_date2_1_, episode0_.episode_number as episode_3_1_, episode0_.name as name4_1_, episode0_.season as season5_1_, episode0_.show_id as show_id7_1_, episode0_.watched as watched6_1_ from episode episode0_ where episode0_.episode_number=(select min(episode1_.episode_number) from episode episode1_ where episode1_.watched=0) and episode0_.season=(select min(episode2_.season) from episode episode2_ where episode2_.watched=0) and episode0_.show_id=? [90110-210]
我尝试过的事情:本机查询,以及这个:
我的存储库:
import model.Episode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Optional;
public interface EpisodeRepository extends JpaRepository<Episode, Long> {
Optional<Episode> findByEpisodeId(Long episodeId);
@Query("from EPISODE where episodeNumber = (SELECT MIN(episodeNumber) FROM EPISODE WHERE watched is false)" +
" AND season = (SELECT MIN(season) FROM EPISODE WHERE watched is false) " +
" AND show.showId = :showId")
Optional<Episode> findNextUnwatchedEpisode(@Param("showId") Long showId);
}
我的实体:
package model;
import lombok.*;
import javax.persistence.*;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
@Entity(name = "EPISODE")
public class Episode {
@Id
@Column(name = "EPISODE_ID", nullable = false)
private Long episodeId;
@Column(name = "NAME", nullable = false)
private String name;
@Column(name = "SEASON", nullable = false)
private Integer season;
@Column(name = "EPISODE_NUMBER", nullable = false)
private Integer episodeNumber;
@Column(name = "AIR_DATE", nullable = false)
private Date airDate;
@Column(name = "WATCHED", nullable = false)
private boolean watched;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="SHOW_ID")
private TVShow show;
}
application.properties:
spring.datasource.url=jdbc:h2:mem:my_tv;DB_CLOSE_ON_EXIT=FALSE;MODE=Oracle;
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
Hibernate ORM 仅从 5.6.5.Final 版本开始支持 H2 2.x.y。旧版本产生无效的 SQL,新版本的 H2 在默认配置中不接受。
您需要检查您的应用程序使用的 hibernate-core
jar 版本并将其更新到某个最新版本(当前版本是 5.6。7.Final)。