簡體   English   中英

我的 Spring 引導項目出現映射異常

[英]I have Mapping Exception on my Spring Boot project

我的項目中有 3 個模型和 1 個表與多對多關系:

@Embeddable
@Getter
@Setter
public class ProductWarehouseId implements Serializable {
     @Column(name = "warehouse_Id")
     private Long warehouseId;
     @Column(name = "product_Id")
     private Long productId;
     @Column(name = "user_Id")
     private Long userId;

     public ProductWarehouseId() {
     }

     public ProductWarehouseId(Long warehouseId, Long productId, Long userId) {
          this.warehouseId = warehouseId;
          this.productId = productId;
          this.userId = userId;
     }

   
}
---------------------------------------------------
@Entity
@NoArgsConstructor
@Getter
@Setter
public class ProductWarehouse {
    @EmbeddedId
    ProductWarehouseId productWarehouseId;


    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("productId")
    @JoinColumn(name = "product_id")
    ProductEntity product ;


    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("warehouseId")
    @JoinColumn(name = "warehouse_id")
    WarehouseEntity warehouse ;


    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("userId")
    @JoinColumn(name = "user_id")
    UserEntity userEntity;


   @Column(name = "stockAmount")
    private Long stockAmount;

    @Column(name = "transctionDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date transactionDate = new Date();

    public ProductWarehouse(ProductEntity product, UserEntity user) {
        this.product = product;
        this.userEntity = user;
    }
}
********************************************************
@Getter
@Setter
@Entity
@RequiredArgsConstructor
public class ProductEntity extends BaseEntity{



    @OneToMany(mappedBy = "product",cascade = CascadeType.ALL)
    private Set<ProductWarehouse> productWarehouses;

//And more veriables
}
------------------------------------
@Getter
@Setter
@Entity
public class WarehouseEntity extends BaseEntity{



 @OneToMany(mappedBy = "warehouse",cascade = CascadeType.ALL)
    private Set<ProductWarehouse> productWarehouses = new HashSet<>();
//and more veriables
}

當我嘗試從 product_warehouse 表中對 select 列表進行更改時,我有一些例外。 我想使用 fromId 和 toId 在倉庫之間轉移產品

我在服務 class 中使用此方法:

 @Override
    @Transactional
    public void transfer(Long fromId, Long toId) {

        WarehouseEntity warehouseEntity = warehouseCRUDRepository.getOne(fromId);
        WarehouseEntity warehouseEntity1 = warehouseCRUDRepository.getOne(toId);
        if (warehouseEntity.getStatus().equals(WarehouseStatus.ACTIVE) && warehouseEntity1.getStatus().equals(WarehouseStatus.ACTIVE)){
            Collection<ProductWarehouse> productWarehouses = em
                    .createNativeQuery("select c from product_warehouse c where c.warehouse_id =:fromId")
                    .setParameter("fromId",fromId)
                    .getResultList();


            for (ProductWarehouse p : productWarehouses){
                p.getProductWarehouseId().setWarehouseId(toId);
                p.setWarehouse(warehouseCRUDRepository.getOne(toId));
            }
        }

    }

例外是:


Servlet.service() 用於路徑 [] 上下文中的 servlet [dispatcherServlet] 引發異常 [請求處理失敗; 嵌套異常是 javax.persistence.PersistenceException: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002] 的根本原因。


你能幫幫我嗎? 對不起我的英語,謝謝。

ProductWarehouse里面已經有Warehouse ,我不明白你為什么要通過在 for 循環中從數據庫中獲取它來再次設置它。

我沒有看到該方法中 for 循環的任何必要性,同樣正如您在上面描述的那樣,您沒有在任何地方定義多對多關系。 在建立關系時,您可以使用連接表,如此所述

如果您需要更多信息,請分享您的需求和您面臨的錯誤的更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM