Reputation: 613
I have a Jpa method like below.
Set<ApplicationMaterialFile> findAllByProcessInstanceIdAndApplicationMaterialIn(String processInstanceId, Collection<ApplicationMaterial> applicationMaterials);
This is the code for call the above Spring Data JPA method. And here will be throw a exception when to call the above Spring Data JPA method.
@Override
public Set<ApplicationMaterialFile> getAllByProcessInstanceIdApplicationMaterialIds(String processInstanceId, Set<Long> applicationMaterialId) {
List<ApplicationMaterial> applicationMaterials = applicationMaterialService.getAllByIdIfNotExistsThenThrowException(applicationMaterialId);
return applicationMaterialFileRepository.findAllByProcessInstanceIdAndApplicationMaterialIn(processInstanceId, applicationMaterials);
}
Here is the ApplicationMaterial entity struct.
/**
*
* @see <a href="https://code.aliyun.com/butterfly-effect/backend/wikis/plans"
* @author himly [email protected]
*/
@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;
}
When to call the Spring Data JPA method findAllByProcessInstanceIdAndApplicationMaterialIn
will throw a exception like below
Caused by: java.lang.IllegalArgumentException: Parameter value element [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)] did not match expected type [com.hikedu.backend.model.ApplicationMaterial (n/a)]
Can someone please help me?
Update:
The table struct:
-- 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)
);
Upvotes: 0
Views: 1220
Reputation: 81862
Spring Data doesn't seem to find your custom method implementation.
Therefore it interprets the method as derived query method and complains that the types of parameters don't match what it expects. The error is strange since it complains, although the types seem to match. But that isn't your problem here. The problem is that the custom method is not found.
Upvotes: 0