hql:将字符串转换为long

时间:2019-04-03 11:25:11

标签: java hql hibernate-mapping

当我尝试在存储库中强制转换字符串时,收到无效请求 如何在不将entity2_ID更改为Entity1内部的对象的情况下将其转换为long?

public class Entity1{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private Long id;
    @Column(name = "Entity2_ID")
    private String entity2_ID;
}

public class Entity2{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID", nullable = false)
    private Long id;
}

public interface Entity1Repository extend JpaRepository<Entity1, Long>{

    @Query("select e1 from Entity1 e1 where cast(e1.entity2_ID as long) in (:entities)")
    List<Entity1> findAllById(@Param("entities") List<Entity2> entities);

}

0 个答案:

没有答案