2013-03-17 68 views
1

我需要一個spring存儲庫方法,可以讓我使用id列表來獲取一個Scene實體列表。當我嘗試引用場景ID時,出現錯誤,稱它無法找到名爲IdScene的屬性。我正在使用自定義查詢來執行此操作。我的查詢有問題嗎?Spring JPA存儲庫查詢找不到ID屬性

我的實體是

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); 
} 
+3

嘗試'SELECT期從場景S其中s.idScene IN(:ID)'注意小寫的 'i' 在 'idScene' – 2013-03-17 10:21:46

+0

@GarethDavis:這應該是一個答案。 – 2013-03-17 10:22:19

+0

謝謝就是這樣。爲什麼我需要使用小寫字母? – user1988235 2013-03-17 12:03:45

回答

2

嘗試:

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

注小寫的 'i' 在 'idScene'」

這是由於Java Bean命名con vention,一個屬性定義爲:

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

限定wibble和不Wibble