1

我需要一个 spring 存储库方法,它可以让我使用 id 列表获取场景实体列表。当我尝试引用场景 ID 时,我得到一个错误,说它找不到名为 IdScene 的属性。我正在使用自定义查询来执行此操作。我的查询有问题吗?

我的实体是

public class Scene implements Serializable
{
private long id_scene;
private Media media;
private int sceneNumber;
private int version;

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id_scene")
public long getIdScene() {
    return id_scene;
}
public void setIdScene(long id_scene) {
    this.id_scene = id_scene;
}

@ManyToOne
@JoinColumn(name = "id_media")
public Media getMedia() {
    return this.media;
}
public void setMedia(Media media) {
    this.media = media;
}

private List<Thumbnail> thumbnails = new ArrayList<Thumbnail>();

@OneToMany(mappedBy = "scene", cascade=CascadeType.ALL,
        orphanRemoval=true)
@LazyCollection(LazyCollectionOption.FALSE)
public List<Thumbnail> getThumbnails() {
    return this.thumbnails;
}
public void setThumbnails(List<Thumbnail> thumbnails) {
    this.thumbnails = thumbnails;
}

public void addThumbnail(Thumbnail thumbnail) {
    thumbnail.setScene(this);
    this.thumbnails.add(thumbnail);
}

private Property property;

@OneToOne(mappedBy="scene", cascade=CascadeType.ALL,
        orphanRemoval=true)
@LazyCollection(LazyCollectionOption.FALSE)
public Property getProperty() {
    return property;
}
public void setProperty(Property property) {
    this.property = property;
}

public void addProperty(Property property) {
    property.setScene(this);
    this.property = property;
}

@Column(name = "sceneNumber")
public int getSceneNumber() {
    return sceneNumber;
}

public void setSceneNumber(int sceneNumber) {
    this.sceneNumber = sceneNumber;
}

@Column(name = "version")
public int getVersion() {
    return version;
}
public void setVersion(int version) {
    this.version = version;
}
}

我的存储库:

public interface SceneRepository extends JpaRepository<Scene, Long> {


public final static String FIND_BY_ID_LIST = "SELECT s"
        + " FROM Scene s WHERE s.IdScene IN (:id)";


@Query(FIND_BY_ID_LIST)
public List<Scene> findByIdScene(@Param("id") List<Long> id);//, Pageable page);
}
4

1 回答 1

2

尝试:

"SELECT s FROM Scene s WHERE s.idScene IN (:id)"

注意'idScene'中的小写'i'”

这是因为 Java Bean 命名约定,一个属性定义为:

public String getWibble() { return wibble; }
public void setWibble(String value) { wibble = value; }

定义wibble而不是Wibble

于 2013-03-17T12:47:09.730 回答