首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >objectdb选择where查询

objectdb选择where查询
EN

Stack Overflow用户
提问于 2013-06-17 02:01:06
回答 1查看 340关注 0票数 0

我尝试使用where子句选择一些实例

代码语言:javascript
复制
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属性:

代码语言:javascript
复制
@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查询出了什么问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-17 14:11:48

值为x1 = 1x2 = 500时,查询变为...

代码语言:javascript
复制
SELECT items FROM RSSItem items
 WHERE items.id <= 1 
   AND items.id >= 500

因为没有id同时为less or equal to 1greater or equal to 500,所以查询将不会给出匹配结果。你想要的可能是;

代码语言:javascript
复制
String query =
        "SELECT items FROM RSSItem items "
        + "WHERE items.id >= :x1 AND "
        + "items.id <= :x2";

包含示例数据的...which将找到1到500之间(包括1和500)的所有id。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17136162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档