我尝试使用where子句选择一些实例
public static List<RSSItem> getRSSItem(int x1, int x2) {
EntityManagerFactory emf = DBHandler.getEmf();
EntityManager em = DBHandler.getEm(emf);
String query =
"SELECT items FROM RSSItem items "
+ "WHERE items.id <= :x1 AND "
+ "items.id >= :x2";
List<RSSItem> results =
(List<RSSItem>) em.createQuery(query).
setParameter("x1", x1).
setParameter("x2", x2).
getResultList();
return results;
}RSSItem属性:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
String title;
String link;
String description;
String pubdate;
String content;
HashMap<String, Integer> keyword = new HashMap();
HashMap<String, Integer> keywordBefore = new HashMap();
// TreeMap <String, Integer> keyword = new TreeMap();
String feed;问题是它总是返回一个大小为0的列表。我的select查询出了什么问题?
发布于 2013-06-17 14:11:48
值为x1 = 1和x2 = 500时,查询变为...
SELECT items FROM RSSItem items
WHERE items.id <= 1
AND items.id >= 500因为没有id同时为less or equal to 1和greater or equal to 500,所以查询将不会给出匹配结果。你想要的可能是;
String query =
"SELECT items FROM RSSItem items "
+ "WHERE items.id >= :x1 AND "
+ "items.id <= :x2";包含示例数据的...which将找到1到500之间(包括1和500)的所有id。
https://stackoverflow.com/questions/17136162
复制相似问题