Please see the following query. When I execute this from Code it gives me
SEVERE: *** ERROR: line 1:491: unexpected token: ( May 3, 2007 11:06:59 AM org.hibernate.hql.ast.ErrorCounter reportError SEVERE: *** ERROR: line 1:562: unexpected token: ( May 3, 2007 11:06:59 AM org.hibernate.hql.ast.ErrorCounter reportError SEVERE: *** ERROR: line 1:588: unexpected token: max May 3, 2007 11:06:59 AM org.hibernate.hql.ast.ErrorCounter reportError SEVERE: *** ERROR: line 1:609: unexpected token: AS
Although this query works perfectly in DB2. Please Note Brackets and syntax is perfectly correct as it works in database.
Its urgent kindly look into the matter.
-------------------------- Query ----------------------------------------- + "SELECT DISTINCT t1.tfzRequestId" + " FROM" + " FzRequestAllowanceViewDE AS t1," + " (" + " SELECT A.tfzDecisionId" + " FROM FzDecisionDE A," + " (" + " SELECT B.tfzRequestId , max (B.decisionDate) AS MAXDECISIONDATE FROM FzDecisionDE B" + " WHERE B.bisFinalized = 'T'" + " AND B.decisionDate <= '2008-12-31 00:00:00.000000'" + " GROUP BY B.tfzRequestId" + " ) AS x" + " WHERE A.tfzRequestId = x.tfzRequestId" //+ " AND A.decisionDate = X.MAXDECISIONDATE" + " AND A.bisFinalized = 'T'" + " GROUP BY A.tfzRequestId, A.tfzDecisionId" + " ) AS t2");
use createCretria() instead of createSqlQuery().You will get lot of Joins and sub queries their
Dhiraj Srivastava
Ranch Hand
Joined: Aug 29, 2001
Posts: 49
posted
0
Hi,
I am putting this query in a String Buffer then pass it to hibernate. As i wrote this query is working perfectly in database but not from the java code.
thanks,
Dhiraj
Dhiraj Srivastava
Ranch Hand
Joined: Aug 29, 2001
Posts: 49
posted
0
Hi,
To be specific following query is not working. I just want to know how can i use a inner query which is aliased with AS.
SELECT A.tfzRequestId, A.tfzDecisionId FROM FzDecisionDE A," + " (SELECT B.tfzRequestId FROM FzDecisionDE B) AS X" + " where A.tfzRequestId = X.tfzRequestId"
We add this query in a String Buffer then we pass this buffer as String in the following method.
HibernateTemplate template = getHibernateTemplate(); list = template.find(pQueryString, pValues);
Thanks
Dhiraj Srivastava
saranga rao
Ranch Hand
Joined: Apr 24, 2007
Posts: 49
posted
0
hi
please go through the createCriteria() and createAllias() then
then you can use this query with out find() which will give an object.
feel free to ask the query of hibernate template using execute() method
Regards saranga
saranga rao
Ranch Hand
Joined: Apr 24, 2007
Posts: 49
posted
0
List lst = (List)getHibernateTemplate().execute(new HiberanteCallback(){
public Object doInHibernate(Session session) throws HibernateException { return session = createCreiter(your main class).add(Expression()). createAllias(your class name(second class name)).add(Expression()).uniqueResult();
} );
this the prefect query you can add as much of table name in allias ,if you want then you can search in the google some of the query will be avaliable