This is my Deal entity :
@Data
@NoArgsConstructor
@Entity
@Table(name = "tbl_deal")
public class Deal {
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@Column(name = "quantity")
private Integer quantity;
@Column(name = "price", precision = 21, scale = 2)
private BigDecimal price;
@Column(name = "is_active")
private Boolean isActive;
@ManyToOne
@JoinColumn(name = "branch")
private Branch branch;
}
This is my Branch entity :
@Data
@NoArgsConstructor
@Entity
@Table(name = "tbl_branch")
public class Branch {
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Size(min = 3, max = 254)
@Column(name = "name", length = 254, nullable = false)
private String name;
@Column(nullable = false)
private String phoneNumber;
}
This is the helper method to build specification :
private Specification<T> fieldLike(String fieldName, String value) {
return (object, cq, cb) -> cb.like(
cb.lower(object.get(fieldName)), "%" + value.toLowerCase() + "%"
);
}
when I pass "branch.name" to this method while querying Deal entity, I get the following exception
org.springframework.dao.InvalidDataAccessApiUsageException: Unable to locate Attribute with the the given name [branch.name] on this ManagedType [com.xxx.Deal]; nested exception is java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [branch.name] on this ManagedType [com.xxx.Deal]