2016-03-04 53 views
0

我們使用的是Spring Boot + Hibernate,其中一個類已經加入了FetchType.EAGER的列。我們想禁用取(簡單地返回空該列),但註釋掉ElementCollection和CollectionTable後,我無法與以下錯誤編譯:在Hibernate上禁用Fetch joinColumn

//@ElementCollection(fetch = FetchType.EAGER) 
//@CollectionTable(name = "gsf_locate_request_pth", joinColumns = {@JoinColumn(name = "locate_id")}) 
@Column(name = "pth_ref") 
private Set<Long> payToHoldRefs; 


Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: gsf_locate_request, for columns: [org.hibernate.mapping.Column(pth_ref)] 

回答

1

註釋@Column(name = "pth_ref")簡單的類型,如僅String。 Hibernate嘗試將Set<Long>放在一個表列中。當然是不可能的。只是使用FetchType.LAZY

@ElementCollection(fetch = FetchType.LAZY) 
@CollectionTable(name = "gsf_locate_request_pth", joinColumns = {@JoinColumn(name = "locate_id")}) 
private Set<Long> payToHoldRefs; 
+0

是否有反正我可以只是簡單地禁用獲取(而不是懶惰)? – enfany

+0

@enfany不知道。另一種方法是使用投影加載對象。 –