当我尝试在存储库中强制转换字符串时,收到无效请求 如何在不将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);
}