博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
双主键关联映射(double primary key)
阅读量:5077 次
发布时间:2019-06-12

本文共 2453 字,大约阅读时间需要 8 分钟。

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;

转载于:https://www.cnblogs.com/sy-liu/p/6890660.html

你可能感兴趣的文章
软件工程团队作业3
查看>>
python标准库——queue模块 的queue类(单向队列)
查看>>
火狐、谷歌、IE关于document.body.scrollTop和document.documentElement.scrollTop 以及值为0的问题...
查看>>
深入理解JVM读书笔记--字节码执行引擎
查看>>
vue-搜索功能-实时监听搜索框的输入,N毫秒请求一次数据
查看>>
批处理 windows 服务的安装与卸载
查看>>
React文档翻译 (快速入门)
查看>>
nodejs fs路径
查看>>
动态规划算法之最大子段和
查看>>
linux c:关联变量的双for循环
查看>>
深入浅出理解zend framework(三)
查看>>
python语句----->if语句,while语句,for循环
查看>>
javascript之数组操作
查看>>
LinkedList源码分析
查看>>
TF-IDF原理
查看>>
用JS制作博客页面背景随滚动渐变的效果
查看>>
JavaScript的迭代函数与迭代函数的实现
查看>>
一步步教你学会browserify
查看>>
Jmeter入门实例
查看>>
亲近用户—回归本质
查看>>