Spring Querying data to get a specific class using Disccriminator

I have classes

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "processType")
public abstract class BaseProcess extends BaseModel {

}

@Entity
public class MainProcess extends BaseProcess {

}

@Entity
public class SubProcess extends BaseProcess {

}


@Entity
public class Tank {

    @Column
    private Long id;

}


@Entity
public class TagAddress {

    @Id
    private Long id

    @ManyToOne
    private BaseProcess process; 

    @ManyToOne
    private Tank tank;  

}

public interface TagAddressDao extends JpaRepository<TagAddress, Long> {

    @Query("FROM TagAddress WHERE tank.id = ?1 AND process.processType = 'MainProcess' ")
    List<TagAddress> findMainProcessByTankId(Long tankId);

    @Query("FROM TagAddress WHERE tank.id = ?1 AND process.processType = 'SubProcess' ")
    List<TagAddress> findSubProcessByTankId(Long tankId);

}

i got this error

org.hibernate.QueryException: Failed to resolve property: processType ...

How can I filter a specific MainProcess and SubProcess class in TagAddressDao?

something like i can do "instanceof MainProcess" or "instanceof SubProcess"

+4
source share

Source: https://habr.com/ru/post/1614222/


All Articles