Reputation: 1
There are 2 existing DAO
There a newly added DAO call ComputerDAO.java
If there is a query as below then what will be the best design ?
Display all university with student name and computer name from the University module.
Expected Output or Sample University Module display
select * from university
join student on uni_id = student_id
join computer on computer_id on uni_id
What is the best DAO Implementation? i.e new class or existing class implementation
Upvotes: 0
Views: 159
Reputation: 27
Looking at the ER diagram, the computer table is not related to the University but to the student table. If there is a student table then there is also a computer table.
For DB support you will be required to use some tools like JPA and hibernate. the relationship could be annotated with OneToOne on name fields.
There are multiple ways you can fetch the desired result. To get started you can look at:
@Query("SELECT name FROM Student s join query ... WHERE u.status = ?1")
Student getStudentData(UUID id);
If you want a list then something like:
@Query("SELECT name FROM Student s join query ...")
Collection<Student> findAll();
use springboot projection if you were to use Springboot, It a very easy and clean.
You can opt-in with a new Service Class name something whatever and use it to bootstrap all these entity classes. You can do like:
ServiceClass {
UniversityRepository unirepo;
StudentRepository studrepo;
List getAllNames() {
listName = [];
// push your names to the blob!!!
return listName;
}
}
Upvotes: 0