How to Create Composite Primary Key | Composite Primary key with Spring boot

  Рет қаралды 8,006

Byte Programming

Byte Programming

Күн бұрын

Пікірлер: 8
@AJ-fb9pk
@AJ-fb9pk 2 жыл бұрын
Primary key: -identifies a row uniquely in a table Composite Primary Key -combination of fields that uniquely identify a row 2 ways to create composite key: 1. @Embeddable 2.@Idclass @Embeddable Key class> -separate class for key fields with @Embeddable in class -the composite key class must be public,implements Serializable, have no args constructor, implement equals and hashcode. Entity class> -Use the key class instead of separate fields in entity for keys -Use @EmbeddedId for composite key class field -for one of the composite key fields having a relation with another entity @MapsId("field_name") must be used for mapping FK -Postman gives Object hierarchy in response body of entity @Idclass Key class> -key fields specified in a separate class Entity class> -key fields specified AGAIN with @Id for each field -@IdClass(KeyClass) -Postman response for entity gives a flat hierarchy of fields
@hapatworld
@hapatworld 2 жыл бұрын
can we do in same file ?
@roshnisannapu2513
@roshnisannapu2513 3 жыл бұрын
Can you share the schema of the tables
@goku6272
@goku6272 3 жыл бұрын
As we know we can define one primary key in a table , can we use primary key with composite primary key .
@ladeharish5514
@ladeharish5514 4 жыл бұрын
As usual great explanation. Interview question - if our table doesn't have primary key, then how will write repository interface for that table. Pls answer...
@ByteProgrammingVedantHarish
@ByteProgrammingVedantHarish 4 жыл бұрын
@Lade Harish : This is a great question. It really test your depth understanding about how @Id works in JPA. Scenario : You want to access some data from third party/external system table. But they have exposed a View to you, for read-only. Solution: 1. You need to identify a column or set of columns that can act as unique for this View. (Hint : If you observe, it is same definition of Primarykey). 2. Once you identify, Mark the field/fields with @Id annotation 3. If single field, we can directly pass datatype in the interface but if multiple fields, do like as we do for composite primary key. Few points i want to highlight : 1. Every entity should have Primary Key defined. Your scenario might be of View..That's why Interviewer has used "table" instead of Entity of View. 2. @Id annotation does not need to be used only when you have primary key in table. 3. If we are able to uniquely identify data with particular field/fields in a table, we can still use those fields with @Id annotation. Hope this helps!
@pratik19901
@pratik19901 4 жыл бұрын
Hello, its nice explanation..thank you. I have some other queries on springboot and Rest. Can you plz share your emailId?
@ByteProgrammingVedantHarish
@ByteProgrammingVedantHarish 4 жыл бұрын
@pratik19901 : bytecoding121@gmail.com
Functional Interfaces in Java
7:02
Byte Programming
Рет қаралды 3,6 М.
Java Unit Testing with JUnit - Tutorial - How to Create And Use Unit Tests
21:35
«Жат бауыр» телехикаясы І 30 - бөлім | Соңғы бөлім
52:59
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 340 М.
$1 vs $500,000 Plane Ticket!
12:20
MrBeast
Рет қаралды 122 МЛН
Kafka Tutorial - Spring Boot Microservices
51:29
Amigoscode
Рет қаралды 447 М.
how Google writes gorgeous C++
7:40
Low Level
Рет қаралды 988 М.
Most Asked Hibernate Interview Questions | Interview Preparation
21:24
Byte Programming
Рет қаралды 10 М.
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 1 МЛН
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 317 М.
Naming Things in Code
7:25
CodeAesthetic
Рет қаралды 2,3 МЛН
Real 10x Programmers Are SLOW To Write Code
14:51
Thriving Technologist
Рет қаралды 71 М.
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 512 М.
Hibernate Interview Questions / Interview Preparation
30:14
Byte Programming
Рет қаралды 20 М.
«Жат бауыр» телехикаясы І 30 - бөлім | Соңғы бөлім
52:59
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 340 М.