JPA实体关系映射

本文介绍了JPA中的实体关系映射,包括单向一对多、双向一对多以及多对多的关系映射。单向一对多允许从父实体查询子实体,双向一对多则支持双向查询。多对多关系映射涉及两个实体间的复杂关联。
摘要由CSDN通过智能技术生成
  今天做东西的时候想用jpa实现商品的repository,有四个表,goods,goods_image,goods_type,goods_and_image
  goods与goods_image为一对多关系,goods_image中存放goods_id和image,一个goods_id可以有多个Image;
  goods与goods_type为多对多关系,goods_and_type存放goods_id和goods_type,每个goods_id可以有多种type,每
个type也是有多种商品;

数据表

create table goods
(
  id          int auto_increment
    primary key,
  name        varchar(50)                         not null,
  description varchar(255)                        null,
  price       int                                 not null,
  status      int default '0'                     null,
  create_time timestamp default CURRENT_TIMESTAMP not null,
  num         int                                 null
);

create table goods_image
(
  `_id`    int auto_increment
    primary key,
  goods_id int          not null,
  remark   varchar(255) null,
  image    varchar(255) not null
);

create table type
(
  type_id int auto_increment
    primary key,
  name    varchar(100)    null,
  parent  int default '0' not null
  comment '父类别 0代表顶级类别'
);
create table goods_and_type
(
  id       int auto_increment
    primary ke
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值