放下這裏我是如何實現這一點。基本上,我們需要從我們需要查詢的一組列中創建一個Hibernate組件(讀取@Embeddable對象)並將其嵌入到主實體中。
的組的列的可如下組合:
@Entity
public class MyEntity{
@Id
private Integer id;
private String col3;
private String col4
@Embedded
private CompositeColumns pairedCol1Col2;
...
...
//Getters Setters
}
:
@Embeddable
public class CompositeColumns{
private String col1;
private String col2;
//Empty constructor is required by Hibernate for instantiation
public CompositeColumns(){
}
public CompositeColumns(String col1, String col2){
this.col1 = col1;
this.col2 = col2;
}
@Column(name="COL1")
public String getCol1(){
}
...
...
//Rest of getters and setters
}
嵌入在如下的主要實體類以上
查詢會再看看如下:
List<CompositeColumns> cols = //get a list of CompositeColumns type
Query query=session.createQuery("from MyEntity where pairedCol1Col2 in (:list)");
query.setParameterList("list", list);
這做這項工作。
注:我跑這一個Oracle數據庫
上你能顯示在這種情況下,宣佈名單的語法? – Angad 2013-02-15 15:47:10