【发布时间】:2012-06-06 08:50:39
【问题描述】:
假设这些是我的实体:
Table1.java
@Entity
public class Table1 {
// Many to one
private Table2 table2;
// Raw attributes
// ...
}
Table2.java
@Entity
public class Table2 {
// Many to one
private Table3 table3;
// Raw attributes
// ...
}
Table3.java
@Entity
public class Table3 {
// Raw attributes
private String lang; // "fr", "en", "de"...
}
我想列出所有 Table1 行中的 table2.table3.lang 等于 en。我尝试通过示例使用查询:
Table3 table3Example = new Table3();
table3Example.setLang("en");
Table2 table2Example = new Table2();
table2Example.setTable3(table3Example);
Table1 table1Example = new Table1();
table1Example.setTable2(table2Example);
table1Repository.findByExample(table1Example);
问题是.findByExample(table1Example)返回数据库的所有行,不管lang,这意味着过滤器根本不考虑:(
任何帮助将不胜感激:)
PS:不抛出异常,.findByExample(table1Example) 只返回所有Table1 行。
【问题讨论】:
标签: java hibernate jpa many-to-one query-by-example