![](/img/trans.png)
[英]How to generate CRUD repository class from entity class spring boot
[英]Entity class for display and for CRUD operation
我正在使用Hibernate 4.1.0和JPA 2.0
我有一個像下面這樣的實體類
@Entity
@Table(name = "V_EMPLOYEES")
public class Employee {
@Id
@Column(name = "EMPLOYEENUMBER")
private String employeeNumber;
@Column(name = "EMPLOYEENAME")
private String employeeName;
@Column(name = "DEPARTMENT")
private String dept;
/ *以上的吸氣器和設置器* /
.....
@Table(name = "V_EMPLOYEES")
在這里V_EMPLOYEES
是一個view
,在此view
,我使用它從查找表中獲取employeename
並與employeeno
V_EMPLOYEES
。
我使用上面的方法在數據表中顯示值,並且工作正常。
我想在用戶單擊“添加”按鈕和一個彈出對話框(用戶輸入employeenumber
, employeestatus
, employeedepartment
等)時創建一個新的雇員記錄。
當我在Entity
類中使用view
時,如果要創建新的雇員記錄,是否應該創建可更新的數據庫view
或創建對Employee
表的新Entity
類引用? 如果出於查看目的,我有一些列不在數據表中,而又想用於創建或更新記錄,該怎么辦?
最佳方法和最佳做法是什么?
我正在使用EntityManager
進行數據提取和持久化(插入,更新和刪除)
任何幫助都是非常明顯的
鑒於這些要求,我將維護兩個單獨的實體,並將公共字段推入映射的超類中:
@MappedSuperclass
public abstract class AbstractEmployee {
@Id
@Column(name = "EMPLOYEENUMBER")
private String employeeNumber;
@Column(name = "EMPLOYEENAME")
private String employeeName;
@Column(name = "DEPARTMENT")
private String dept;
// Constructor, getters, setters
}
@Entity
@Table(name = "V_EMPLOYEES")
public class ReadOnlyEmployee extends AbstractEmployee {
}
@Entity
@Table(name = "EMPLOYEES")
public class Employee extends AbstractEmployee {
// Extra mappings here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.