当前位置:网站首页>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;
}
边栏推荐
- Keywords implements and @override
- Bean创建流程 与 lazy-init 延迟加载机制原理
- What to do when the alicloud SSL certificate expires
- On mask culling of unity
- 史上最全的Redis基础+进阶项目实战总结笔记
- 0 basic unity course. Bricklaying
- Draw on screen border in Commodore 64
- The most comprehensive summary notes of redis foundation + advanced project in history
- JPA复合主键使用
- Unreal 4 learning notes - set player birth point
猜你喜欢

為什麼win10開熱點後電腦沒有網絡?

Wildcard SSL certificate issuing time

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

UE4 method of embedding web pages

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

Free travel recommendation in Bangkok: introduction to the Mekong River in Bangkok

The golden deer, a scenic spot in London -- a sailing museum that tells vivid sailing stories

Process architecture and process management

Unreal 4 learning notes - set player birth point

Unity automatic pathfinding
随机推荐
Draw on screen border in Commodore 64
圆心科技,很焦虑?
Unity3d lookat parameter description
Network layer protocol hardware
Detailed explanation of cookies and sessions
Brew install NVM command not found solution
Detailed explanation of the process of "flyingbird" small game (camera adjustment and following part)
Collective system
A must see cruise experience in Bangkok: visit the Mekong River and enjoy the scenery on both sides of the river
Unreal 4 unavigationsystemv1 compilation error
Network high concurrency
Oculus quest2 development: (I) basic environment construction and guide package
Create a simple battle game with photon pun
0 basic unity course. Bricklaying
Photon pun refresh hall room list
Check London attractions suitable for parents and children in winter vacation
Deep learning ----- different methods to realize inception-10
【Paper】2020_ Research on defense and evaluation strategy of heterogeneous UAV formation_ Zuojiankai
Moore Manor diary I: realize the reclamation, sowing, watering and harvest in Moore Manor
Enlist soldiers and generals, draw small programs, multi-threaded display time