无法转换实体中具有@IdClass的请求元素
2022-09-03 12:41:57
我有以下设置:
@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 Data 存储库: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
你知道我做错了什么吗?谢谢!