繁体   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