我有以下設置:未能請求元素轉換成實體@IdClass
@Entity
@IdClass(MemberAttributePk.class)
public class MemberAttribute {
@Id
@ManyToOne @JoinColumn(name="member_id")
protected Member member;
@Id
protected String name;
private String value;
public MemberAttribute() {}
// get & set
}
和ID類:
public class MemberAttributePk implements Serializable {
protected Member member;
protected String name;
public MemberAttributePk() {}
// get & set
}
我已經定義了一個簡單的Spring數據存儲庫MemberAttribute
:
@Repository
public interface MemberAttributeRepo extends JpaRepository<MemberAttribute, MemberAttributePk> {
}
現在,我想要做的就是將成員屬性保存到數據庫中:
public void saveAttribute(Member member, String name, String value) {
MemberAttribute attr = new MemberAttribute(member, name, value);
attributeRepo.save(attr);
}
不過,我結束了與此服務器例外:
2016-08-28 00:24:20.673 WARN 5656 --- [nio-8080-exec-8] .w.s.m.s.DefaultHandlerExceptionResolver :
Failed to convert request element: org.springframework.beans.ConversionNotSupportedException:
Failed to convert property value of type [java.lang.Long] to required type [com.example.Member] for property 'member'; nested exception is java.lang.IllegalStateException:
Cannot convert value of type [java.lang.Long] to required type [com.example.Member] for property 'member':
no matching editors or conversion strategy found
任何想法,我究竟做錯了什麼? 謝謝!
謝謝!而已。小成員提到'Member'應該被映射爲:'@ManyToOne @JoinColumn(name =「member_id」,可插入= false,可更新= false)' – Ionut