当前位置:网站首页>JPA composite primary key usage
JPA composite primary key usage
2022-06-30 04:50:00 【Xuanyuan longer】
JPA Composite primary keys use
1、 Create a table with a composite primary key User
This table uses username+phone As a composite component
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 An entity class that creates a composite primary key in
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
@Data
@Entity
public class UserKey implements Serializable {
private String username;
private String phone;
}
3、 Create the entity class of the table
Use... On entity classes @IdClass Annotation specifies the composite primary key . meanwhile , Need to be in name and phone Field @Id Annotations are marked as primary keys
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;
}
边栏推荐
- Steamvr causes abnormal scene camera
- Implementation of one interview question one distributed lock every day
- How to repair expired SSL certificates?
- 深度学习------不同方法实现Inception-10
- Detailed explanation of the process of "flyingbird" small game (camera adjustment and following part)
- 【Paper】2015_ Coordinated cruise control for high-speed train movements based on a multi-agent model
- Window10 jar double click to run without response
- Connect to the database and run node JS running database shows that the database is missing
- [control] multi agent system summary. 5. system consolidation.
- Oculus quest2 development: (I) basic environment construction and guide package
猜你喜欢

Check London attractions suitable for parents and children in winter vacation

Have a heart beating Valentine's day in Singapore

力扣589:N 叉树的前序遍历

Directory operations and virtual file systems

Malignant bug: 1252 of unit MySQL export

Connect to the database and run node JS running database shows that the database is missing

Unreal 4 learning notes - data storage using blueprints

Method of applying for code signing certificate by enterprise

Foreign SSL certificate

Yolov5 torch installation
随机推荐
Learning about signals
Brew install NVM command not found solution
Malignant bug: 1252 of unit MySQL export
Interprocess communication
Deeply understand the function calling process of C language
Keywords implements and @override
EasyRecovery数据恢复软件 恢复了我两年前的照片视频数据
圆心科技,很焦虑?
System programming summary
JPA复合主键使用
Enlist soldiers and generals, draw small programs, multi-threaded display time
UE4 method of embedding web pages
The difference between get and post requests
Pourquoi l'ordinateur n'a - t - il pas de réseau après l'ouverture du Hotspot win10?
Cheap SSL certificate abroad
Unity automatic pathfinding
harbor api 2.0查询
Circle center technology, very anxious?
力扣2049:统计最高分的节点数目
Collective system