0

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]

Shree Naath
  • 477
  • 2
  • 5
  • 18
  • 1
    There is no property "branch.name". You have to break them out into separate calls - get("branch").get("name"). – Chris Dec 11 '22 at 21:59

0 Answers0