Aymen Kanzari
Aymen Kanzari

Reputation: 2023

spring data - query in array in object

I have an EstablishmentEntity which has an array of Attachment, i want to get the EstablishmentEntity that its Attachments contains an Attachment that its idChild equals the parameter i pass

@Entity
@DiscriminatorValue
public class EstablishmentEntity extends ExerciseFrameworkEntity {

    @ElementCollection
    private Set<Attachment> attachments;

}

public class Attachment implements Serializable {

    private static final long serialVersionUID = 1L;

    private String idChild;

}

I tried with this, but i get this error

Parameter value element [xxxxxxxx] did not match expected type Attachment

@Repository
public interface EstablishmentRepository extends JpaRepository<EstablishmentEntity, String> {
    
    EstablishmentEntity findByAttachmentsIn(String idChild);
    
}

Upvotes: 0

Views: 1440

Answers (1)

Eklavya
Eklavya

Reputation: 18450

findByAttachmentsIn expect List of Attachment for In query but you are passing String.

Use IdChild instead of In in method naming as you search by idChild of Attachment

EstablishmentEntity findByAttachmentsIdChild(String idChild);

Upvotes: 1

Related Questions