0

following is the query:

    Query q = getSession().createQuery("FROM secroles 
                           WHERE secroles.SR_ORG = :srOrg , 
                                 secroles.SR_PROFILE= :srUser, 
                                 ISDELETED=:isDeleted");

error:

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: , near line 1, column 37 [FROM secroles WHERE SR_ORG = :srOrg , SR_PROFILE= :srUser , ISDELETED = :ISDELETED]

complete function:

public String getSecroleByOrgNID(Organization srOrg, Profile srUser){try {
        System.out.println("bug is here0");
        begin();
        Query q = getSession().createQuery("FROM secroles WHERE secroles.SR_ORG = :srOrg , secroles.SR_PROFILE= :srUser , ISDELETED=:isDeleted");
        q.setParameter("srOrg", srOrg);
        q.setParameter("srOrg", srUser);
        q.setBoolean("isDeleted", false);
        Secroles sr = (Secroles) q.uniqueResult();
        Roletable rt = sr.getSrRole();
        commit();
        return rt.getRoleName();
    } catch( HibernateException e ) {
        rollback();
        e.printStackTrace();
        System.out.println("Could not assign role\n Message: "+e.getMessage());
    }
return null;

}

}

3 Answers 3

2

You put , instead of AND, I presume.

Also you should use class property names not column names. So probably secroles.srOrg instead of secroles.SR_ORG

Sign up to request clarification or add additional context in comments.

6 Comments

not working, getting the error: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: , near line 1, column 37 [FROM secroles WHERE secroles.srOrg = :SR_ORGsrOrg , secroles.srUser= :SR_PROFILE , ISDELETED = :ISDELETED]
Are you sure it's the same error? Are you using property names as I suggested? 'Cause your names look like column names. What I suggest - assign your query to the variable, and print it. Then post output with exact error message.
Also what is secroles? It should be class name.
initializing the variable to null and then assigned query to the variable and getting nothing in the output.
In HQL you should speak classes and properties language. Not tables and columns. Use its mapped class name instead and corresponding properties.
|
2

Use AND instead of "," for multiple clauses. Refer to the documentation on how to use WHERE clause: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html

FROM secroles 
WHERE secroles.SR_ORG = :srOrg AND
      secroles.SR_PROFILE= :srUser AND
      ISDELETED=:isDeleted

Comments

0

Also you bind the same parameter twice using different variables according to the code above. I'm pretty sure that won't do what you expect.

    q.setParameter("srOrg", srOrg);
    q.setParameter("srOrg", srUser);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.