Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java createQuery中创建此查询字符串?_Java_Sql_Hibernate_Jpa_Native - Fatal编程技术网

如何在java createQuery中创建此查询字符串?

如何在java createQuery中创建此查询字符串?,java,sql,hibernate,jpa,native,Java,Sql,Hibernate,Jpa,Native,我正在尝试使用Hibernate或本机SQL或java返回产品对象列表,但我无法使代码正常工作,如果有人帮助我,我将不胜感激,非常感谢, 这就是逻辑: ... ArrayList<Product> prodList = new ArrayList<Product>(); EntityManager entityManager = this.entityManager; try { //the logic of following query is: selec

我正在尝试使用Hibernate或本机SQL或java返回产品对象列表,但我无法使代码正常工作,如果有人帮助我,我将不胜感激,非常感谢, 这就是逻辑:

 ...
 ArrayList<Product> prodList = new ArrayList<Product>();
EntityManager entityManager = this.entityManager;
try 
{

  //the logic of following query is: select all records from prodTable table where productDate is
//passed 2 months than today's date(something list today's day minus productDate is 2 months), 
//and then the records are not existed in prodCategory table by the key of ProductID and 
//productCategory combination. So the prodList is the combination of the above two conditions. 
//something like this:

 String queryString = "select p from prodTable p where (today - p.ProductDate) greaterThan 2  
months AND p is not in (select c from prodCategory c where c.ProductID = p.ProductID and 
c.category = '09' ) //need help of this line of query.

 prodList = entityManager.createQuery(queryString).getResultList();
 return prodList;
} catch (Exception e) {

throw e;
} …

尝试以下内容

 ...
 ArrayList<Product> prodList = new ArrayList<Product>();
EntityManager entityManager = this.entityManager;
try 
{

 String queryString = "select p from prodTable p where (today - p.ProductDate) greaterThan 2  
months AND p is not in (select c from prodCategory c where c.ProductID = p.ProductID and 
c.category = '09' )"; //need help of this line of query.

 prodList = entityManager.createSQLQuery(queryString).getResultList();
 return prodList;
} catch (Exception e) {

throw e;
}

注意:我使用了SQLQuery,因此您可以在编写查询时放置查询。希望有帮助。

看起来您的字符串没有结束引号。具体来说,您遇到了什么问题?我的queryString示例代码只是一个示例,用于向您展示我想要的内容,但此代码不可编译,我需要帮助来编写完整的代码:String queryString=select p from prodTable p其中today-p.ProductDate大于2个月,p不在select c from prodCategory c其中c.ProductID=p.ProductID和c.category='09'谢谢您的帮助,但在我测试之前,我认为您的代码基本上不会工作,你只需在我的代码末尾添加,就像我说的,我的代码只是一个示例,它根本不是编译的,例如:greaterThan,不在等。我只是想给你一个我想要的想法,我们需要完全重新编写它,请让我知道你是否有任何想法来编写一个完全兼容的代码。再次感谢。