我试图通过 idfindById方法获取行,但它没有成功,无法在 DB 中找到行。当我findAll之前打电话时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);}实体@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)}
1 回答
喵喵时光机
TA贡献1846条经验 获得超7个赞
您所有的 ManyToOne 关系都是非可选的或非空的。
所以 Hibernate 生成 INNER JOINS。您必须确保您的数据遵循此规则。
如果您定义非可选或非空关系,您还应该对数据库表中的外键设置 NOT NULL 约束。
添加回答
举报
0/150
提交
取消