title: PostgreSQL: ERROR: operator does not exist: integer = record - Spring JPA Data
body: <p>I'm during creation a simple application. It includes 3 tables - 2 of them - many to many. That means <strong>Category</strong>, <strong>WordConfig</strong> and <strong>Word</strong>. Below I'll show you models of these classes.</p>
  
  <p><strong>Category.java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "categories")
  @NoArgsConstructor
  @Data
  @AllArgsConstructor
  public class Category {
  
      public interface CategoryValidation {}
  
      @Id
      @Column(name = "id_category")
      @GeneratedValue(strategy = GenerationType.AUTO)
      @NotNull
      private int id;
  
      @Column(name = "name")
      @NotBlank(groups = {CategoryValidation.class})
      @Length(min = 1, max = 30, groups = {CategoryValidation.class})
      @Pattern(regexp = "^[a-zA-Z0-9_'/ ]+$", groups = {CategoryValidation.class})
      private String name;
  
      @Column(name = "mode")
      @NotNull(groups = {CategoryValidation.class})
      @Enumerated(EnumType.STRING)
      private Mode mode;
  
      @Column(name = "id_parent")
      private int idParent;
  
      @Column(name = "defaultCategory", updatable = false)
      private boolean defaultCategory;
  
      @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
      @JoinColumn(name = "id_test")
      @JsonIgnore
      @ToString.Exclude
      private Test test;
  
      @ManyToMany(fetch = FetchType.LAZY, mappedBy = "categories", cascade = CascadeType.ALL)
      private List&lt;WordConfig&gt; wordConfigs = new ArrayList&lt;&gt;();
  }
  </code></pre>
  
  <p><strong>WordConfig.java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "wordConfigs")
  @NoArgsConstructor
  @Data
  @AllArgsConstructor
  public class WordConfig {
      public interface WordConfigValidation {}
  
      @Id
      @Column(name = "id_wordConfig")
      @GeneratedValue(strategy = GenerationType.AUTO)
      @NotNull
      private int id;
  
      @Column(name = "done")
      private boolean done;
  
      @Column(name = "today")
      private boolean today;
  
      @Column(name = "repeated")
      private int repeated;
  
      @Column(name = "thisUnit")
      private boolean thisUnit;
  
      @Column(name = "dateTimeDone", updatable = false)
      private Timestamp dateTimeDone;
  
      @Column(name = "processNo")
      private int processNo;
  
      @Column(name = "lastPerfectNum")
      private int lastPerfectNum;
  
      @Column(name = "lastPerfect")
      private boolean lastPerfect;
  
      @Column(name = "comment")
      private String comment;
  
      @Column(name = "mechanism")
      @NotNull(groups = {WordConfigValidation.class})
      @Enumerated(EnumType.STRING)
      private Mechanism mechanism;
  
      @ManyToMany(cascade = CascadeType.ALL)
      @JoinTable(
              name = "CategoryWordConfig",
              joinColumns = { @JoinColumn(name = "id_wordConfig") },
              inverseJoinColumns = { @JoinColumn(name = "id_category") }
      )
      List&lt;Category&gt; categories = new ArrayList&lt;&gt;();
  
      @OneToMany(fetch = FetchType.EAGER, mappedBy = "wordConfig",cascade = CascadeType.ALL)
      @Fetch(value = FetchMode.SUBSELECT)
      private List&lt;Word&gt; words;
  
  }
  </code></pre>
  
  <p><strong>Word.java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "words")
  @NoArgsConstructor
  @Data
  @AllArgsConstructor
  public class Word {
  
      public interface WordValidation {}
  
      @Id
      @Column(name = "id_word")
      @GeneratedValue(strategy = GenerationType.AUTO)
      @NotNull
      private int id;
  
      @Column(name = "word")
      private String word;
  
      @Column(name = "basicWord")
      private String basicWord;
  
      @Column(name = "seat")
      private int seat;
  
      @Column(name = "toSpeech")
      private boolean toSpeech;
  
      @Column(name = "answer")
      private boolean answer;
  
      @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
      @JoinColumn(name = "id_wordConfig")
      @JsonIgnore
      @ToString.Exclude
      private WordConfig wordConfig;
  }
  </code></pre>
  
  <p>To describe my problem I have to show you repository of WordConfig:
  <strong>WordConfigRepository.java</strong></p>
  
  <pre><code>@Repository
  public interface WordConfigRepository extends CrudRepository&lt;WordConfig, Long&gt; {
  
      List&lt;WordConfig&gt; findWordConfigsByCategories(List&lt;Category&gt; categories);
  }
  </code></pre>
  
  <p>And the last one - service where I use presented method of repository: (a bit simplified)</p>
  
  <pre><code>public void testWithCategoryAndWords(Test test) {
      List&lt;Category&gt; categories = new ArrayList&lt;&gt;();
  
      //1. categories.add(test.getCategories().get(1));
      //2. categories.add(test.getCategories().get(2));
  
      wordConfigRepository.findWordConfigsByCategories(categories);
  }
  </code></pre>
  
  <p>How does it work and what is the problem?
  I get category from test, add it to created list and I use the repository method to get wordConfig list. When I uncomment just one of the commented lines, everything works correctly. The problem occurs when I uncomment both of presented lines. This is the error:</p>
  
  <pre><code>org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = record
    No operator matches the given name and argument types. You might need to add explicit type casts.
    Pozycja: 693
      at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) ~[postgresql-42.2.5.jar:42.2.5]
      at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) ~[postgresql-42.2.5.jar:42.2.5]
      at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) ~[postgresql-42.2.5.jar:42.2.5]
      at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) ~[postgresql-42.2.5.jar:42.2.5]
      at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) ~[postgresql-42.2.5.jar:42.2.5]
      at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143) ~[postgresql-42.2.5.jar:42.2.5]
  ...
  </code></pre>
  
  <p>Compilator shows that is some problem with type casting, but why it is working with one element in array list of categories, but not with 2 or more? Should I try created some custom @Query maybe with native query? Is there somewhere problem with me code?</p>