我有一个如下的Jpa方法。
Set<ApplicationMaterialFile> findAllByProcessInstanceIdAndApplicationMaterialIn(String processInstanceId, Collection<ApplicationMaterial> applicationMaterials);
这是用于调用上述Spring Data JPA方法的代码。调用上述Spring Data JPA方法时,将引发异常。
@Override
public Set<ApplicationMaterialFile> getAllByProcessInstanceIdApplicationMaterialIds(String processInstanceId, Set<Long> applicationMaterialId) {
List<ApplicationMaterial> applicationMaterials = applicationMaterialService.getAllByIdIfNotExistsThenThrowException(applicationMaterialId);
return applicationMaterialFileRepository.findAllByProcessInstanceIdAndApplicationMaterialIn(processInstanceId, applicationMaterials);
}
这是ApplicationMaterial实体结构。
/**
*
* @see <a href="https://code.aliyun.com/butterfly-effect/backend/wikis/plans"
* @author himly z1399956473@gamil.com
*/
@Table(name = "application_material_library")
@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
@ToString(exclude = {"university"})
@EqualsAndHashCode(exclude = {"university"})
public class ApplicationMaterial {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String name;
private String fileFormat;
private String description;
private String templateFileUrl;
@JsonIgnore
@ManyToOne
private University university;
@CreatedDate
@Column(nullable = false)
private Timestamp createdAt;
@LastModifiedDate
@Column(nullable = false)
private Timestamp updatedAt;
}
何时调用Spring Data JPA方法findAllByProcessInstanceIdAndApplicationMaterialIn
会引发如下异常
由于:java.lang.IllegalArgumentException:参数值元素 [ApplicationMaterial(id = 1,name = sdfsf,fileFormat = doc, description = dfsdfds,templateFileUrl = fsdfsdf,createdAt = 2018-09-26 16:54:09.297,updatedAt = 2018-09-26 16:54:23.451)]不匹配 预期的类型[com.hikedu.backend.model.ApplicationMaterial(n / a)]
有人可以帮我吗?
更新:
表结构:
-- auto-generated definition
create table application_material_library
(
id bigint auto_increment
primary key,
created_at datetime(6) not null,
description varchar(255) null,
file_format varchar(255) null,
name varchar(255) not null,
template_file_url varchar(255) null,
updated_at datetime(6) not null,
university_id bigint null,
constraint FK9kuemh1kjhyt8u16sqw6i6t59
foreign key (university_id) references universities (id)
);
答案 0 :(得分:0)
Spring Data似乎找不到您的自定义方法实现。
因此,它将方法解释为派生查询方法,并抱怨参数类型与期望值不匹配。该错误很奇怪,因为它抱怨,尽管类型似乎匹配。但这不是您的问题。问题是找不到自定义方法。