對於JPA實現的hibernate實體的下劃線無法轉換問題

這個問題困擾了我很久,最後終於解決了,廢話不多說。


User這個實體類裏面有如下

 @ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "accounts_id")
	public Accounts getAccounts() {
		return this.accounts;
	}

這時候如果我在action裏面調用了

User user = userService.getByProperties("accounts_id", account.getId());

就會報錯

could not resolve property: accounts_id of: com.pwq.entity.User [select o from com.pwq.entity.User o where 1=1 and o.accounts_id=:accounts_id]

但是改成下面的就OK了

User user = userService.getByProperties("accounts.id", account.getId());

如果實體裏面帶下劃線的字段是一個基本對象如Integer、String等,如

@Column(name = "test_id")
	public Integer getTestId() {
		return this.testId;
	}
因爲和hibernate的映射機制有關的,所以把abc_def改成abcDef就可以了
List<Testtable> tb0 = testtablesr.criteriaEqeals("testId", 321);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章