当前位置: 首页 > 知识库问答 >
问题:

Java Hibernate Java.lang.IllegalArgumentException:参数值与预期类型不匹配

平航
2023-03-14

在游戏实体中我有:

私有集 genres=新哈希集<>();

@Query("select new com.twognation.hub.dto.GameDTO(game.id, game.name, game.active, game.description, game.coverImage, game.logo, game.backgroundImage, game.featuredImage, game.characterImage, game.smallCoverImage, count(tournament.id) as tournamentCount) from Game game left join Tournament tournament on game.id=tournament.game inner join game.genres genres where lower(game.name) like CONCAT('%', :name, '%') and genres IN (1301) group by game.id order by tournamentCount desc, game.id")
@Query("select new com.twognation.hub.dto.GameDTO(game.id, game.name, game.active, game.description, game.coverImage, game.logo, game.backgroundImage, game.featuredImage, game.characterImage, game.smallCoverImage, count(tournament.id) as tournamentCount) from Game game left join Tournament tournament on game.id=tournament.game inner join game.genres genres where lower(game.name) like CONCAT('%', :name, '%') and genres IN (:genres) group by game.id order by tournamentCount desc, game.id")
    Page<GameDTO> findAllOrderByTournamentCountAndGenreFilter(@Param("name") String name, @Param("genres") String genres, Pageable page);

我得到这个错误:

Caused by: java.lang.IllegalArgumentException: Parameter value [1301] did not match expected type [com.twognation.hub.domain.GameGenre (n/a)]
    at org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:54)
    at org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:27)
    at org.hibernate.query.internal.QueryParameterBindingImpl.validate(QueryParameterBindingImpl.java:90)
    at org.hibernate.query.internal.QueryParameterBindingImpl.setBindValue(QueryParameterBindingImpl.java:55)
    at org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:486)
    at org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:104)
    at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:139)
    at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.bind(StringQueryParameterBinder.java:61)
    at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:101)
    at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.bind(SpelExpressionStringQueryParameterBinder.java:76)
    at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:161)
    at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:152)
    at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doCreateQuery(AbstractStringBasedJpaQuery.java:81)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:190)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$PagedExecution.doExecute(JpaQueryExecution.java:186)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:87)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:116)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:492)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:475)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    ... 172 common frames omitted

游戏实体:

@Entity
@Table(name = "game")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "game")
public class Game implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    private Long id;

    @Column(name = "name")
    private String name;

    @Column(name = "active")
    private Boolean active;

    @Lob
    @Column(name = "description")
    private String description;

    @Column(name = "cover_image")
    private String coverImage;

    @Column(name = "logo")
    private String logo;

    @Column(name = "background_image")
    private String backgroundImage;

    @Column(name = "featured_image")
    private String featuredImage;

    @Column(name = "character_image")
    private String characterImage;

    @Column(name = "small_cover_image")
    private String smallCoverImage;

    @ManyToMany
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    @JoinTable(name = "game_genres",
               joinColumns = @JoinColumn(name="games_id", referencedColumnName="id"),
               inverseJoinColumns = @JoinColumn(name="genres_id", referencedColumnName="id"))
    private Set<GameGenre> genres = new HashSet<>();

共有1个答案

子车安和
2023-03-14

您可能需要传递GameGenre类型的对象,而不是字符串。也可能是GameGenre对象的集合。

 类似资料:
  • 它打印出值的等效,这是因为这一行: 通过调用表示。 那么,如何使Hibernate相信是的实例? 我的枚举是由加载的。而由URLClassLoader加载,由另一个类加载器加载。

  • 当我想跑的时候: 我得到: 执行操作“MappingAddAction”的服务异常,java.lang.IllegalArgumentException:参数值[5118]与预期的类型[com.vernuso.trust.server.domain.ClientImport.MappingInfo(N/A)]不匹配 有人能帮助我理解为什么它需要类型而不是类型吗? 我有两个表,如下图所示。Mappi

  • 我做错了什么? 正在更新: 我发现了问题所在。问题与ActionRepository中找到的函数有关。函数的签名首先要求两个日期进行比较,然后id和我给出了相反的值。我很清楚,在我上了它之后,我会有一个问题的日期,所以答案确实帮助了我。谢谢大家!

  • 我得到的错误. 我对此感到困惑,因为它来自下面显示的被注释掉的服务方法。当我把它注释掉时,错误就避免了。列是一个,即或。 实体: 我的存储库: 我的服务: 当我取消注释时

  • 这是我运行程序时收到的错误: 注:[19533]是我使用的一个测试值。 这是在CustomerServiceBeanImpl.java中出现错误的方法: 在快速检查ERD时,“Customer”表中的“id”列的数据类型为bigint。然而,我不确定这是否重要。(顺便提一下PostgreSQL数据库。) 如何修复此错误?

  • 问题内容: 我收到以下错误 java.lang.IllegalArgumentException: Parameter value [2] did not match expected type [com.cityBike.app.model.User (n/a)] at org.hibernate.jpa.spi.BaseQueryImpl.validateBinding(BaseQueryIm