skip to Main Content

I have this table:

@Entity
@Table(name = "t_tropical",
        uniqueConstraints =
        @UniqueConstraint(columnNames = {
                "name",
                "sign",
                "isRetro",
                "house",
                "lang"}))
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
public class Tropical {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private String sign;
    private Boolean isRetro;
    private Integer house;
    private String lang;
    private Date updateDate;
    
}

and this method:

@Repository
public interface TropicalRepository extends JpaRepository<Tropical, Long> {

    Tropical findByHouseIsAndSignAndIsRetroAndLangIs
            (Integer house, String sign, Boolean retro, String lang);

}

but does not seems to work. I found for existing house / sign / isRetro and land and return null

2

Answers


  1. The correct query should look as follows using the JPA naming conventions:

    @Repository
    public interface TropicalRepository extends JpaRepository<Tropical, Long> {
    
        Tropical findByHouseAndSignAndIsRetroAndLang
                (Integer house, String sign, Boolean retro, String lang);
    
    }
    

    In your query there seemed to be an Is appended to House and to Lang. These cannot be resolved based on the attributes in your entity.

    Login or Signup to reply.
  2. Please make sure you are following spring Data JPA naming conventions as documented here: spring-data-derived-queries.

    In your example you seem not to follow those

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search