放下这里我是如何实现这一点。基本上,我们需要从我们需要查询的一组列中创建一个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