【发布时间】:2020-08-13 16:35:42
【问题描述】:
我有一个正在运行的 Spring Boot CRUD 应用程序,只要我使用常规 MySQL 表。但是我需要显示来自多个表的数据,所以我创建了一个 MySQL 视图。但是现在得到以下错误:
创建类中定义的名称为“entityManagerFactory”的 bean 时出错 路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: 调用 init 方法失败;嵌套异常是 org.hibernate.AnnotationException:没有为实体指定标识符: net.tekknow.medaverter.domain.AppointmentView
我在关注这个例子: https://www.javabullets.com/calling-database-views-from-spring-data-jpa/
这是域对象:
package net.tekknow.medaverter.domain;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.Size;
@Entity
@Table(name = "vw_appointments")
public class AppointmentView implements Serializable {
@Size(max = 32)
@Column(name="Date")
public String date;
@Column(name="Physician")
public String physician;
@Column(name="LabCollected")
public Timestamp labCollected;
@Column(name="Note")
public String note;
public String getDate_time() {
return date;
}
public String getPhysician() {
return physician;
}
public Timestamp getDatetime_collected() {
return labCollected;
}
public String getNote() {
return note;
}
}
这是视图的 mysql 查询,只是为了向您展示它的工作原理:
mysql> 从 vw_appointments 中选择 *; +------------+-------------+---------+ -------------------+ |日期 |医师 |实验室收藏 |注意 | +------------+-------------+---------+ -------------------+ | 2010 年 10 月 29 日 |坎贝尔,J | 2010-10-29 11:09:00 |没有可用的注释| +------------+-------------+---------+ -------------------+ 1 行在集合中(0.02 秒)
这里是服务代码:
@Service
@Transactional
public class AppointmentViewService {
@Autowired
AppointmentViewRepository repo;
public List<AppointmentView> listAll() {
return repo.findAll();
}
}
这里是存储库代码:
public interface AppointmentViewRepository extends JpaRepository<AppointmentView,Integer> {}
Hibernate 不处理视图吗?有什么建议吗?
【问题讨论】:
标签: java hibernate spring-boot jpa