title: Spring Data JPA filter Data in subclass with own query
body: <p>I am working on a little JAVA project to improve my work with passwords. For this i use a H2 database to store the data and Spring data JPA as OR-Mapper. All DML operation works fine, but I do not want to allow the user to delete passwords from the database. For this I add a field in the Bean named DML_ART. The DML_ART is a string field, which is the state of the row. For example, if the user clicks on the JSF GUI on delete, the flag will set to "DELETE".</p>
  
  <p>On the load of the data this line is to ignore. The SQL Query Works for DBPasswordEntity, but the subclass has also to filter by the same criteria. </p>
  
  <p>But the written statement is not valide. And I dont know why.</p>
  
  <p><strong>DBPasswordEntity.java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "PasswordEntity",schema = "pwdmanager")
  @PrimaryKeyJoinColumn(name = "password_id", referencedColumnName = "id")
  @Getter
  @Setter
  public class DBPasswordEntity extends DBMetaDataEntity implements Serializable {
  
      @Basic
      @Column(name = "PASSWORD", nullable = false, length = 4000)
      private String password;
  
      @OneToMany(fetch = FetchType.EAGER,cascade = ALL, mappedBy = "password")
      private Set&lt;DBExtendEntity&gt; extend;
  
      @Transient
      public void addExtend(DBExtendEntity ex)
      {
          if(extend == null)
          {
              extend = new LinkedHashSet&lt;&gt;();
          }
          extend.add(ex);
      }
  
     }
  </code></pre>
  
  <p><strong>DBExtendEntity.java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "ExtendEntity",schema = "pwdmanager")
  @PrimaryKeyJoinColumn(name = "extend_id", referencedColumnName = "id")
  @Getter
  @Setter
  public class DBExtendEntity extends DBMetaDataEntity implements Serializable{
  
      @Basic
      @Column(name = "NAME", nullable = false, length = 255)
      private String name;
  
      @ManyToOne(optional = false)
      @JoinColumn(name = "password", referencedColumnName = "Password_ID")
      private DBPasswordEntity password;  
  }
  </code></pre>
  
  <p><strong>DBMetaDataEntity</strong></p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.JOINED)
  @DiscriminatorColumn(name = "pwd_type")
  @Table(name = "MetaDataEntity",schema = "pwdmanager")
  @Data
  public abstract class DBMetaDataEntity {
  
      @Id
      @Column(name = "ID", nullable = false)
      @GeneratedValue(strategy= GenerationType.IDENTITY)
      private Integer id;
  
      @Basic
      @Column(name = "DML_ART", nullable = false)
      private String dml_art ="INSERT";
  }
  </code></pre>
  
  <p><strong>SQL-Filter-Operation</strong></p>
  
  <pre><code>@Transactional
  public interface PasswordRepository  extends JpaRepository&lt;DBPasswordEntity,String&gt; {
  
      @Query(value="SELECT pwd FROM DBPasswordEntity pwd WHERE pwd.dml_art &lt;&gt; 'DELETE' AND pwd.extend.id IN (SELECT  ext.id FROM DBExtendEntity ext where ext.dml_art &lt;&gt; 'DELETE')")
      List&lt;DBPasswordEntity&gt; findAll_DML_ART();
  }
  </code></pre>