0

I have a query:

<query name="getMaxId">
       <![CDATA[from  Identifier where value = (select MAX (cast(value, integer)) from Identifier where type = :type) ]]>
    </query>

where value is: <property name="value" type="java.lang.String" column="value" not-null="true"/>

and try to invoke it with:

Query q = getSession().getNamedQuery("getMaxId");
q.setString("type", type);
List<Identifier> results = q.list();

However I get an error:

Exception: org.hibernate.exception.SQLGrammarException: could not execute query Caused by: java.sql.SQLSyntaxErrorException: ORA-01722: invalid number

I also tried

<![CDATA[from  Identifier where value = (select MAX (to_number(value)) from Identifier where type = :type) ]]>

but then I receive

Caused by: java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.AggregateNode

2
  • Please add the complete stacktrace Commented Jan 17, 2023 at 13:14
  • And the problem SQL. Commented Jan 17, 2023 at 13:34

1 Answer 1

0

Not the proper solution to this problem but kind of workaround is pure SQL instead of HQL:

createSQLQuery("SELECT MAX (to_number(value)) FROM ids");
Sign up to request clarification or add additional context in comments.

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.