We have a query:
List<Book> books = session.createQuery(
"from Book b where :x member of b.bookCategories")
.setParameter("x", crimeStory)
.list();
But when executing this query, we got a warning message:
WARN 10:19:41 deprecation: HHH90000016: Found use of deprecated
'collection property' syntax in HQL/JPQL query [null.elements];
use collection function syntax instead [elements(null)].
I tried to change the query to:
List<Book> books = session.createQuery(
"from Book b where ? in elements(b.bookCategories)")
.setParameter(0, crimeStory).list();
but the warning message was still there.
Please help me to fix this warning.
P/s: We are currently using Hibernate 5.0.2
It is legal JPA and so should not be deprecated. See also http://download.oracle.com/otndocs/jcp/persistence-2.0-fr-oth-JSpec/.
See https://hibernate.atlassian.net/browse/HHH-10621 for the JIRA about this bug.
You could just hide the message by adding log4j.logger.org.hibernate.orm.deprecation=error
to your log4j.properties
.
(I know this was an old question but it is used in the JIRA call)
Instead of using MEMBER OF
, rather use an INNER JOIN
. The JSQL should then be
from Book b inner join b.bookCategories bc where bc.id = :categoryId
Reference: https://stackoverflow.com/a/8340001/67796
As a side note, to simply hide (not fix) messages like this, as of 2017 and Log4j2, use org.hibernate.orm.deprecation
, for example:
<Logger name="org.hibernate.orm.deprecation" additivity="false" level="WARN">
<RegexFilter regex=".*HHH90000016.*" onMatch="DENY" onMismatch="NEUTRAL"/>
…
</Logger>
Be sure to use the specific code for your particular deprecation message, in this particular case it was HHH90000016
, but for Criteria-API deprecation warnings it would be HHH90000022
, and so on.
Or to disable all Hibernate deprecation messages (not recommended):
<Logger name="org.hibernate.orm.deprecation" additivity="false" level="ERROR">
…
</Logger>