HI, I think I'll have to make it a little bit more clear in the docs as well. I Knew about Hibernate comments and assumed they could be used as hints.
Now, that I look back on the Query API I see they were added in 4.3: http://docs.jboss.org/hibernate/orm/4.3/javadocs/org/hibernate/Query.html#addQueryHint(java.lang.String) But I can't find it in 4.2: http://docs.jboss.org/hibernate/orm/4.2/javadocs/org/hibernate/Query.html I will adjust my PR accordingly so that the comment on @NamedQuery will only be propagated if the associated Hibernate property is set. As for @NamedNativeQuery, I think we need to support it since we have the comment attribute on the annotation level. Vlad On Tue, Aug 1, 2017 at 6:16 PM, Steve Ebersole <st...@hibernate.org> wrote: > See inline.. > > On Tue, Aug 1, 2017 at 9:05 AM Vlad Mihalcea <mihalcea.v...@gmail.com> > wrote: > >> I created a new Pull Request so that comments can be handled for named >> queries (even for UPDATE/DELETE queries): >> >> https://github.com/hibernate/hibernate-orm/pull/1970 >> > > Not really following this. See `org.hibernate.annotations.NamedQuery#comment` > and `org.hibernate.annotations.QueryHints#COMMENT`. So we do support > this for named queries. Hints are generally only useful (if at all) for > SELECTs. Comments can be useful for any type of statement, but again we > have the support for those in place in regards to named queries. > > > I think we should add two new issues; >> >> 1. So that we could pass Query Hints for Named (Native) Queries as well. >> Right now we can only pass comments which are appended at the beginning of >> the SQL statement. >> > > I completely disagree about supporting comments and/or hints for native > SQL queries. > > As for "[we only support] comments which are appended at the beginning of > the SQL statement" - that is true for comments. However, it is inaccurate > for hints - see `org.hibernate.dialect.Dialect#getQueryHintString`. So > the hook is in place for handling this for hints. There is no such hook > for comments - do you concretely know of a Dialect that supports a comment > elsewhere than the start? I'm a little leery of adding support for this > pre-6.0 as we know for certain that this will change (String-based versus > AST-based). If you wan to add such a hook in 6.0, I am ok with that - > provided you can show me such a concrete use case. > > > > >> 2. I see we support Query Hints for Oracle and SQL Server. We should >> support MySQL as well: >> >> https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html >> > > Sure - I think its a good idea to support this where ever the underlying > database supports it. > > > If you have time to take a look on the PR, let me know what you think. >> > > I'll take a look at the PR after we resolve these general points and they > are incorporated into the PR. > > > _______________________________________________ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev