0

I have a kind of same but a but different question as asked Syntax for input parameters in a MySQL query.

At the above link the query is implemented with @ Variables. I have implemented a query with ?. it's not working.. the code is here

String queryString = "from OptimumMeasure as model where model.id.goalId= ? " +
    " and model.id.questionId= ? and model.id.attributeId= ?"; 
        Query queryObject = getSession().createQuery(queryString);
        queryObject.setParameter(0, goalId);
        queryObject.setParameter(1, questionId);
        queryObject.setParameter(2, attributeId);
        return queryObject.list()

Thanks in advance.

6
  • How is it not working? Are you getting an error message? Commented Jan 12, 2015 at 23:20
  • Actually its running, but its not taking the values of variables.. Commented Jan 12, 2015 at 23:24
  • Are you using java persistence? I think you are confusing sql prepared statements syntax with java persistence syntax. See positional parameters at the bottom here docs.oracle.com/javaee/6/tutorial/doc/bnbrg.html Commented Jan 12, 2015 at 23:31
  • @Phil_1984_ Yes, I was confused , Thanks. I am using Java persistence. It's not returning the values. It's passing NULL to other method where I am calling it. I don't know why its so. Commented Jan 12, 2015 at 23:45
  • I think you are using hibernate right? Commented Jan 13, 2015 at 0:13

1 Answer 1

0

Just a guess, but it seems highly unlikely that you have an "id" attribute that would be anything but an id.

Try using the attribute name of the linked object and then its id:

from OptimumMeasure as model
where model.goal.id = ?
and model.quaestion.id = ?
and model.attribute.id= ?
Sign up to request clarification or add additional context in comments.

1 Comment

Bohemian .. No no. its not like this. It is ok with the syntax but have some problem with returning the values to other method.

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.