Я пытаюсь выполнить представление mysql в Spring Boot, но получаю следующую ошибку:
java. sql .SQLSyntaxErrorException: неизвестный столбец 'assignmen0_.lab_collected' в 'список полей'
Но очевидно, что переменная lab_collected существует в компоненте домена. Должно ли имя столбца совпадать? Я хочу, чтобы он отображался как «LabCollected», а не «lab_collected».
Вот вывод из представления, просто чтобы показать вам, что он работает:
mysql> select * from vw_appointments;
+----+------------+-------------+---------------------+-------------------+
| id | Date | Physician | LabCollected | Note |
+----+------------+-------------+---------------------+-------------------+
| 1 | 10/29/2010 | CAMPBELL, J | 2010-10-29 11:09:00 | no note available |
+----+------------+-------------+---------------------+-------------------+
Вот боб домена:
package net.tekknow.medaverter.domain;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Size;
@Entity
@Table(name = "vw_appointments")
//Prevent changes from being applied by Hibernate
@org.hibernate.annotations.Immutable
public class AppointmentView implements Serializable {
// Identifier. Has to be Integer as you implement JpaRepository<AppointmentView,Integer>
@Id
private Integer id;
public Integer getId() {
return this.id;
}
@Size(max = 32)
@Column(name="Date")
public String date;
@Column(name="Physician")
public String physician;
@Column(name="LabCollected")
public Timestamp lab_collected;
@Column(name="Note")
public String note;
public String getDate() {
return date;
}
public String getPhysician() {
return physician;
}
public Timestamp getLabCollected() {
return lab_collected;
}
public String getNote() {
return note;
}
}
Вот контроллер:
@RestController
public class AppointmentViewController {
@Autowired
AppointmentViewService appointmentViewService;
@CrossOrigin
@GetMapping("/appointment_view")
public List<AppointmentView> viewAppointmentsPage(Model model) {
List<AppointmentView> appointments = appointmentViewService.listAll();
return appointments;
}
}
Вот служба:
@Service
@Transactional
public class AppointmentViewService {
@Autowired
AppointmentViewRepository repo;
public List<AppointmentView> listAll() {
return repo.findAll();
}
}
Вот хранилище:
public interface AppointmentViewRepository extends JpaRepository<AppointmentView,Integer> {}
Есть предложения?