今天要給一個實體類添加一個List集合屬性!
private List<Reverts> childList = new ArrayList<Reverts>();
寫完後get/set方法一寫,啓動就報錯:
org.hibernate.MappingException: Could not determine type for: java.util.List, at table: T_REVERTS, for columns: [org.hibernate.mapping.Column(childList)]
解決辦法:在屬性的get方法上加上一段註解標識它是臨時屬性,不是數據庫字段就OK
- @Transient
- public List<Reverts> getChildList() {
- return childList;
- }
- public void setChildList(List<Reverts> childList) {
- this.childList = childList;
- }
記得導入的是:import javax.persistence.Transient;