【发布时间】: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