zoukankan      html  css  js  c++  java
  • 双主键关联映射(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;

  • 相关阅读:
    ioctl()函数详解
    傻孩子菜单框架
    高级套接口-(sendmsg和recvmsg)
    Linux内核Socket CAN中文文档
    第二节 信息系统服务管理
    第一节 信息化知识
    关系数据库标准语言SQL——概述
    SQL分组函数
    如何将web项目部署到weblogic
    范式
  • 原文地址:https://www.cnblogs.com/sy-liu/p/6890660.html
Copyright © 2011-2022 走看看