当前位置:网站首页>JPA复合主键使用
JPA复合主键使用
2022-06-30 04:45:00 【轩辕龙儿】
1、建立带有复合主键的表User
该表使用 username+phone 做为复合组件
create table user
(
username varchar(50) not null,
phone varchar(11) not null,
email varchar(20) default '',
address varchar(50) default '',
primary key (username, phone)
) default charset = utf8
2、java中建立复合主键的实体类
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
@Data
@Entity
public class UserKey implements Serializable {
private String username;
private String phone;
}
3、建立表的实体类
在实体类上面使用 @IdClass 注解指定复合主键。同时,需要在 name 和 phone 字段上面使用 @Id 注解标记为主键
import lombok.Data;
import javax.persistence.*;
@Data
@Entity
@Table(name = "user")
@IdClass(value = UserKey.class)
public class User {
@Id
@Column(nullable = false)
private String username;
@Id
@Column(nullable = false)
private String phone;
@Column
private String email;
@Column
private String address;
}
边栏推荐
- [fpga] implementation of IIC read / write EEPROM
- Unreal 4 learning notes - Animated Montage
- Free travel recommendation in Bangkok: introduction to the Mekong River in Bangkok
- Efficiency test of adding and querying ArrayList and LinkedList
- The golden deer, a scenic spot in London -- a sailing museum that tells vivid sailing stories
- 【Paper】2015_ Active fault-tolerant control system design with trajectory re-planning against actuator
- [learn FPGA programming from scratch -52]: high level chapter - FPGA development based on IP core - basic framework for IP core use (taking PLL as an example)
- 破局存量客群营销,试一下客户分群管理(含聚类模型等实操效果评估)
- 【Paper】2017_ Distributed control for high-speed trains movements
- 力扣周赛293题解
猜你喜欢

The most comprehensive summary notes of redis foundation + advanced project in history

输入输出及中断技术——微机第六章学习笔记

Introduction to some representations, neighbors and degrees of Graphs

Foreign SSL certificate

【Paper】2015_ Active fault-tolerant control system design with trajectory re-planning against actuator
![[UGV] schematic diagram of UGV version 32](/img/4b/03471d2cc96be5d57c97fd1c4e17dc.jpg)
[UGV] schematic diagram of UGV version 32

Window10 jar double click to run without response

【Paper】2013_ An efficient model predictive control scheme for an unmanned quadrotor helicopter
![[UAV] gyroscope data analysis, taking Victor intelligent jy901b as an example](/img/d7/7bf43437edb87b69cdc5ae858f44e1.jpg)
[UAV] gyroscope data analysis, taking Victor intelligent jy901b as an example

Network high concurrency
随机推荐
【Paper】2017_ Distributed control for high-speed trains movements
Transport layer protocol tcp/udp
Bean创建流程 与 lazy-init 延迟加载机制原理
Redis实现短信登入功能(二)Redis实现登入功能
Keywords implements and @override
股票利益【非dp】
Lambda&Stream
Free travel recommendation in Bangkok: introduction to the Mekong River in Bangkok
Qos(Quality of Service)
Qos(Quality of Service)
[UAV] kinematic analysis from single propeller to four rotor UAV
【Paper】2015_ Coordinated cruise control for high-speed train movements based on a multi-agent model
【Paper】2015_ Active fault-tolerant control system design with trajectory re-planning against actuator
[UGV] schematic diagram of UGV version 32
Introduction to some representations, neighbors and degrees of Graphs
Internship: interface case implementation
BeanFactory创建流程
Break through the existing customer group marketing, and try customer grouping management (including clustering model and other practical effect evaluation)
Collective system
【Paper】2021_ Analysis of the Consensus Protocol of Heterogeneous Agents with Time-Delays