Sebastian D'Agostino
Sebastian D'Agostino

Reputation: 1675

Not retrieving a OneToOne relationtionship Object in Spring Data JPA CrudRepository

I am using the following implementation of Crud Repository, where I need to find if MyObject contains a reference to OtherObject.

public interface MyRepository extends CrudRepository<MyObject, Long> {
    List<MyObject> findByOtherObject(Long id);
}

This is how I map my entity:

@Entity
@Table(name = "mytable")
public class MyObject {
    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "object_id")
    private OtherObject otherObject;
}

And the error I am getting:

java.lang.IllegalArgumentException: Parameter value [3] did not match expected type

This shows that I am mapping incorrectly between my Entity and my Repository. But I do not want to change the name of the column.

It does not work if I change the repository method to findByObject_Id. Any suggestion?

Upvotes: 0

Views: 327

Answers (1)

Amr Alaa
Amr Alaa

Reputation: 553

try to use

findByOtherObjectId(Long id)

Upvotes: 2

Related Questions