我試圖通過 idfindById方法獲取行,但它沒有成功,無法在 DB 中找到行。當(dāng)我findAll之前打電話時(shí)findById工作正常。我使用 PostgreSQL。public void updateOffer(OrderOfferDTO orderOfferDTO) { // List<OrderOfferEntity> all = orderOfferRepository.findAll(); OrderOfferEntity orderOfferEntity = orderOfferRepository.findById(orderOfferDTO.getId()).orElse(null); assert(orderOfferEntity != null); if (!isCanOfferUpdate(orderOfferEntity)) return; orderOfferEntity.setNumberOffer(orderOfferEntity.getNumberOffer() + 1); orderOfferEntity.setOfferDelivery(orderOfferDTO.getOfferDelivery()); orderOfferEntity.setOfferPickup(orderOfferDTO.getOfferPickup()); orderOfferRepository.save(orderOfferEntity); }資料庫@Repositorypublic interface OrderOfferRepository extends JpaRepository<OrderOfferEntity, Long> { OrderOfferEntity findByUserEntityAndOrderEntity(UserEntity userEntity, OrderEntity orderEntity); List<OrderOfferEntity> findByUserEntityNotAndOrderEntity(UserEntity supplierEntity, OrderEntity orderEntity); List<OrderOfferEntity> findByOrderEntity(OrderEntity orderEntity); List<OrderOfferEntity> findByUserEntity(UserEntity userEntity);}實(shí)體@Entity@Table(name = "AUCTION_SUPPLIER")@Datapublic class OrderOfferEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "NUMBER_OFFER") private Integer numberOffer; @Column(name = "OFFER_PICKUP") private Integer offerPickup; @Column(name = "OFFER_DELIVERY") private Integer offerDelivery; @Column(name = "IS_ACCEPTED") private Boolean isAccepted; @ManyToOne(optional = false) @JoinColumn(name = "DELIVERY_PROGRESS_ID") private DeliveryProgressEntity deliveryProgressEntity; @ManyToOne @JoinColumn(name = "SUPPLIER_ID", nullable = false) private UserEntity userEntity; @ManyToOne @JoinColumn(name = "CUSTOMER_ORDER_ID", nullable = false) private OrderEntity orderEntity; @ManyToOne @JoinColumn(name = "FACTORY_ID", nullable = false)}
我厭倦了用 JpaRepository 做點(diǎn)什么但是找不到行 findById ,
動(dòng)漫人物
2023-06-21 16:39:35