在这里写下我如何实现此目标。基本上,我们需要从需要查询的列集中制作一个Hibernate组件(读取@Embeddable对象),并将其嵌入到主实体中。
列组可以如下组合:
@Embeddablepublic 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}将上述内容嵌入到您的主要实体类中,如下所示:
@Entitypublic class MyEntity{ @Id private Integer id; private String col3; private String col4 @Embedded private CompositeColumns pairedCol1Col2; ... ... //Getters Setters}该查询将如下所示:
List<CompositeColumns> cols = //get a list of CompositeColumns typeQuery query=session.createQuery( "from MyEntity where pairedCol1Col2 in (:list)" );query.setParameterList( "list", list );
这样就可以了。
注意:我在Oracle数据库上运行了



