当前位置:网站首页>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;
}
边栏推荐
- 為什麼win10開熱點後電腦沒有網絡?
- 【Paper】2006_ Time-Optimal Control of a Hovering Quad-Rotor Helicopter
- The role of break
- Malignant bug: 1252 of unit MySQL export
- Webots learning notes
- Is the Flink connector JDBC open source? Where can I download it
- 【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey
- Tea mall system based on SSM framework [project source code + database script + report]
- 深度学习------不同方法实现Inception-10
- Imile uses Zadig's multi cloud environment to deploy thousands of times a week to continuously deliver global business across clouds and regions
猜你喜欢

What to do when the alicloud SSL certificate expires

Marvel fan welfare: Singapore Madame Tussauds Wax Museum Marvel 4D experience Museum

System programming summary

【Paper】2013_ An efficient model predictive control scheme for an unmanned quadrotor helicopter

Using the command line to convert JSON to dart file in fluent

Qos(Quality of Service)

harbor api 2.0查询

Issue SSL certificate with IP address

Break through the existing customer group marketing, and try customer grouping management (including clustering model and other practical effect evaluation)

Connect to the database and run node JS running database shows that the database is missing
随机推荐
Threejs realizes the simulation of river, surface flow, pipe flow and sea surface
Singapore parent-child tour, these popular attractions must be arranged
Websocket implementation principle
Unreal 4 learning notes - Animated Montage
史上最全的Redis基础+进阶项目实战总结笔记
This connection is not a private connection this website may be pretending to steal your personal or financial information
The most comprehensive summary notes of redis foundation + advanced project in history
Introduction to system programming
Recommended cultural landmarks of these tourist attractions in Bangkok
Why does the computer have no network after win10 is turned on?
Qos(Quality of Service)
A must see cruise experience in Bangkok: visit the Mekong River and enjoy the scenery on both sides of the river
MySQL查询小工具(一)json格式的字符串字段中,替换json数组中对象的某个属性值
【Paper】2015_ Active fault-tolerant control system design with trajectory re-planning against actuator
harbor api 2.0查询
Difference between request forwarding and redirection
Malignant bug: 1252 of unit MySQL export
One interview question and one joint index every day
[control] multi agent system summary. 5. system consolidation.
Use of thread pool