Unable to locate appropriate constructor on class報錯原因以及解決方案


再使用HQL語句通過封裝查詢時,會添加一個虛擬的實體類
 例如

select new com.musicworld.vo.ComUserSong(c.commentId,c.commentTime,c.content,c.userinfo.userName) from Comment c
 這種封裝需要實體類提供對應構造器

構造方法

public ComUserSong(Integer commentId, Date commentTime, String content,
			String userName) {
		super();
		this.commentId = commentId;
		this.commentTime = commentTime;
		this.content = content;
		this.userName = userName;
	}

 但使用中經常會拋這樣的異常:Unable to locate appropriate constructor on class。

出現這個異常需要檢查以下幾種情況:
1)參數構造器的參數類型是否正確
2)參數構造器的順序和hql中的順序是否一致
3)參數構造器的參數個數是否和hql中的個數一致
4)參數構造器的參數類型是否TimeStamp

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