Could someone tell how to create a composite key in Spring Data JPA using Mongo DB
You cannot use MongoDB with Spring Data JPA because JPA is for relational databases like MySQL.
Instead you have to use Spring Data MongDB and you will find the documentation here:
https://docs.spring.io/spring-data/mongodb/docs/2.1.8.RELEASE/reference/html/
But here's an example with a composite key:
class StudentChairman {
@Id
private CompositeKey id;
// getters and setters
static class CompositeKey implements Serializable {
private String studentId;
private String groupId;
// getters and setters
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With