Quote:
create relationships between entities in a project that is being written from scratch, or specify what relationships to have between them?
That's the best part about an ORM. You don't need to think about it yourself (apart from some index, FK-related constraints), an ORM handles the relationship itself. For example, see the following Java code:
public class Teacher {
int id;
String name;
}
public class Subject {
int id;
String name;
String code;
}
Then, you can build a relationship between these as (many-to-many):
public class Lecture {
int id;
int teacherId;
int subjectId;
}
Here, a teacher is linked to a subject. What's important is that your Java code "relates" a teacher to multiple subjects and a single subject can be taught by multiple teachers. This is a many-to-many relationship. Hibernate (an other ORMs) automatically translate this relationship to the native SQL queries that generate the tables for you.
java - Code First Apprach with Hibernate - Stack Overflow[
^]
Tutorial: Hibernate, JPA - Part 1 - Java Code Geeks - 2021[
^]
Quote:
how can we identify the entities that have a difficult relationship in a short time?
You cannot do that automatically, in your first project. Once you have built a few projects and deployed applications — that crashed and caused some late night debugging — you will get a sense of what to do. For example, as soon as you mentioned "
relationship between the person and the address", I thought of the address type as being an embedded relationship. Continue to develop a project, see how its performance can be improved and use the documentation of the framework to learn best practices.
https://www.baeldung.com/jpa-embedded-embeddable[
^]
Check out the documentation about the relational database (not only) from Oracle:
IBM Docs - Relational Database[
^].