【问题标题】:Hibernate Micronaut Data JPA: Named parameter not bound : p1Hibernate Micronaut Data JPA:未绑定命名参数:p1
【发布时间】:2022-01-13 23:32:58
【问题描述】:

我目前正在使用 Micronaut Data 创建一个带有 psql 数据库的简单应用程序,并且我正在使用 CrudRepository 进行查询。但是,在尝试使用“findBySymbol”查询时,我不断收到以下错误:

    [default-nioEventLoopGroup-1-3] ERROR io.micronaut.http.server.RouteExecutor - Unexpected error occurred: Named parameter not bound : p1
org.hibernate.QueryException: Named parameter not bound : p1

这是我的实体:

 @Entity(name = "quote")
@Table(name = "quote", schema = "mn")
@Data
@Introspected
public class QuoteEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ManyToOne(targetEntity = SymbolEntity.class)
    @JoinColumn(name = "symbol", referencedColumnName = "value")
    private SymbolEntity symbol;

    private BigDecimal bid;

    private BigDecimal ask;
    @Column(name = "last_price")
    private BigDecimal lastPrice;

    private BigDecimal volume;
    
}

和存储库:

@Repository
public interface QuotesRepository extends CrudRepository<QuoteEntity, Integer> {

    @Override
    List<QuoteEntity> findAll();

    Optional<QuoteEntity> findBySymbol(SymbolEntity symbol);
}

以及我正在拨打电话的控制器:

 @Operation(summary = "Returns a quote for the given symbol via JPA fetched from the DB")
    @ApiResponse(content = @Content(mediaType = MediaType.APPLICATION_JSON))
    @ApiResponse(responseCode = "400", description = "Invalid symbol")
    @Tag(name = "Quotes")
    @Get("/{symbol}/jpa")
    public HttpResponse getQuoteViaJPA(@PathVariable String symbol) {
        final Optional<QuoteEntity> quote = repository.findBySymbol(new SymbolEntity(symbol));
        if (quote.isEmpty()) {
            final CustomError notFound = CustomError.builder()
                    .status(HttpStatus.NOT_FOUND.getCode())
                    .error(HttpStatus.NOT_FOUND.name())
                    .message("Quote for symbol not available in DB")
                    .path("/quotes/" + symbol + "/jpa")
                    .build();
            return HttpResponse.notFound(notFound);
        }
        return HttpResponse.ok(quote.get());
    }

有没有人知道问题出在哪里?

【问题讨论】:

  • 你用的是什么版本?旧版本中存在类似的错误。
  • 啊,是的!我将版本从 3.2.2 改回 3.0.0,这似乎解决了这个问题。谢谢你的建议:)

标签: java hibernate jpa psql micronaut


【解决方案1】:

3.2.2 版本的 Micronaut-data-hibernate-jpa 似乎存在问题,将版本更改回 3.0.0 似乎已经解决了问题。

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。
  • 我希望最新版本能够修复它。你能用一种重现它的方式报告这个问题吗?谢谢!
猜你喜欢
  • 2021-04-05
  • 1970-01-01
  • 2021-08-13
  • 2020-01-10
  • 2015-02-28
  • 2019-05-29
  • 2020-05-31
  • 2016-01-26
  • 1970-01-01
相关资源
最近更新 更多