• 双主键关联映射(double primary key)


    A Foreign key refering com.wawagame.backend.trade.hbentity.ProductEntity from com.wawagame.backend.trade.hbentity.OrdersEntity has the wrong number of column. should be 2

    当一个表里有双主键:

    在进行多对一映射时:

    当该表作为one的一方是时:

    再多的一方的entity里用注解进行映射要关联两个主键:

    例子如下:

    OrdersEntity 多的一方

    @Entity
    @Table(name = "orders", schema = "", catalog = "game")
    public class OrdersEntity {
    @Id
    @Column(name = "serialNumber")
    private String serialNumber;
    @Basic
    @Column(name="userId")
    private String userId;
    @Basic
    @Column(name = "appId")
    private String appId;
    @Basic
    @Column(name = "productId")
    private long productId;
    @Basic
    @Column(name = "quantity")
    private long quantity;
    @Basic
    @Column(name = "price")
    private long price;
    @Basic
    @Column(name = "status")
    private byte status;
    @Basic
    @Column(name = "paymentPlat")
    private String paymentPlat;
    @Basic
    @Column(name = "createTime")
    private long createTime;
    @Basic
    @Column(name = "paymentTime")
    private Long paymentTime;
    @Basic
    @Column(name = "totalPrice")
    private long totalPrice;
    @Basic
    @Column(name = "clientIp")
    private String clientIp;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "appId",insertable = false,updatable = false)
    private AppEntity appEntity;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
    @JoinColumn(name = "productId", insertable = false, updatable = false),
    @JoinColumn(name = "appId", insertable = false, updatable = false)
    })
    private ProductEntity productEntity;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "userid",insertable = false,updatable = false)
    private UserEntity userEntity;

     PoductEntity一的一方

    public class ProductEntityPK implements Serializable {
    @Column(name="productId")
    @Id
    private long productId;
    @Column(name="appId")
    @Id
    private String appId;

    @Entity
    @Table(name = "product", schema = "" , catalog = "game")
    @IdClass(ProductEntityPK.class)
    public class ProductEntity {
    @Id
    @Column(name = "appId")
    private String appId;
    @Id
    @GeneratedValue
    @Column(name = "productId")
    private long productId;
    @Basic
    @Column(name = "productName")
    private String productName;
    @Basic
    @Column(name = "productDesc")
    private String productDesc;
    @Basic
    @Column(name = "price")
    private long price;
    @OneToMany(mappedBy = "productEntity",fetch = FetchType.LAZY)
    private Set<OrdersEntity> ordersEntity = new HashSet<OrdersEntity>();
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="appId",insertable = false, updatable = false)
    private AppEntity appEntity;

  • 相关阅读:
    N个数字每X个数字组成一组,求组数
    生成带文本的UIImage
    Linux创建环境变量(Mac OS)
    为UIView绘制单边的boder
    ecshop之随机文章
    微软继MVC5后,出现ASP.NET VNEXT
    本科毕业生转正之前谈待遇
    ecshop title优化
    百度地图开发之一】申请Key和配置初览显示地图
    项目总结—jQuery EasyUI-DataGrid 拼表及查看详情
  • 原文地址:https://www.cnblogs.com/sy-liu/p/6890660.html
Copyright © 2020-2023  润新知