java命名查询未知::dropwizard hibernate

um6iljoc  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(244)

我有一个实体类定义为:

@Entity
@Table(name = "some_table")
@NamedQueries({
        @NamedQuery(name = "SomeTable.getSomeTableForAmount",
                query = "select x from SomeTable x where :amount >= x.startingAmount AND :amount <= x.endingAmount " +
                        "AND product = :product"
        )
})

@Getter
@Setter
public class SomeTable {
    @Id
    private String id;
    private BigDecimal startingAmount;
    private BigDecimal endingAmount;
    private BigDecimal minimumDueAmount;
    private Product product;
}

该类的dao如下所示:

public class SomeTableDao extends AbstractDAO<SomeTable> implements ISomeTableDao {
    @Inject
    public SomeTableDao(SessionFactory sessionFactory) {
        super(sessionFactory);
    }

    @Override
    public Optional<SomeTable> getSomeTableForAmount(BigDecimal amount, Product product) {
        return namedQuery("SomeTable.getSomeTableForAmount")
                .setParameter("amount", amount)
                .setParameter("product", product)
                .setMaxResults(1)
                .list()
                .stream()
                .map(s -> (SomeTable) s)
                .findFirst();
    }
}

从资源执行此操作时,我将面临异常声明 Named query not known: SomeTable.getSomeTableForAmount 资源方法用 @UnitOfWork .
我还注意到查询没有添加到 namedQueryDefinitionMapNamedQueryRepository .

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题