• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make this createQuery SQL codes working?

 
Peter Cong
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to Hibernate or native SQL or java to return a list of Product objects, but I can not make the code working, I appreciate if anybody help me, thanks a lot,
This is the logic:
...
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;
}
...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please TellTheDetails. Just saying "not working" doesn't give us any clues to work with. Also see ItDoesntWorkIsUseless

Also, why this?
If you're not going to handle the exception in some way, why bother catching it?
 
Peter Cong
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Please TellTheDetails. Just saying "not working" doesn't give us any clues to work with. Also see ItDoesntWorkIsUseless

Also, why this?
If you're not going to handle the exception in some way, why bother catching it?


Basically, I need help how to code 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.

The catch part is not the major, I will deal it later. thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic