Я пытаюсь написать следующий собственный запрос SQL, но у меня есть ошибка, которую я не могу решить.
Я хотел бы написать запрос SQL родной ...
мне нужна твоя помощь:)
AssignmentDao:
``@Repository
public interface AssignmentDao extends JpaRepository<Assignment, Integer> {
@Query(value ="SELECT project.PROJECT_NAME, contributor.FIRST_NAME, assignment.START_DATE, assignment.END_DATE from assignment join contributor on assignment.CONTRIBUTOR_id=contributor.id join project on assignment.PROJECT_ID_PROJECT=project.ID_PROJECT", nativeQuery=true)
List<Assignment> fetchAssignmentDataInnerJoin();
AssignmentServiceimpl:
@Service("assignmentService")
public class AssignmentServiceImpl implements AssignmentService {
@Resource
private AssignmentDao assignmentDao;
public List<Assignment> fetchAssignmentDataInnerJoin(){
List<Assignment> list = assignmentDao.fetchAssignmentDataInnerJoin();
return list;
AppController:
@GetMapping({"/listAssignments"})
public String listAssignment(ModelMap model) {
List<Assignment> assignments = assignmentService.fetchAssignmentDataInnerJoin();
model.addAttribute("assignments", assignments);
System.out.println("Liste des affectations : " + assignments);
return "allAssignments";
}
application.properties:
# Configurations H2
spring.jpa.show-sql=true
spring.h2.console.enabled=true
# Configuration MariaDB
spring.datasource.url=jdbc:mariadb://localhost:3308/dbmycapla
spring.datasource.username=***
spring.datasource.password=***
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.jpa.properties.hibernate.format_sql=true
#spring.jpa.hibernate.ddl-auto=create-drop
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
А вот и ошибка:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [SELECT project.PROJECT_NAME, contributor.FIRST_NAME, assignment.START_DATE, assignment.END_DATE from assignment join contributor on assignment.CONTRIBUTOR_id=contributor.id join project on assignment.PROJECT_ID_PROJECT=project.ID_PROJECT]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLSyntaxErrorException: No such column: id_assignment
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query