使用Discriminator获取具体类的Spring Data查询

时间:2015-11-03 06:02:58

标签: java inheritance spring-data discriminator

我有这个课程

@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);

}

我收到了这个错误

  

org.hibernate.QueryException:无法解析属性:processType ...

如何使用TagAddressDao中的具体类MainProcess和SubProcess进行过滤?

我可以做的事情是“instanceof MainProcess”或“instanceof SubProcess”

0 个答案:

没有答案