How to put a comment into HQL (Hibernate Query Language)?

妖精的绣舞 提交于 2019-12-10 12:36:11

问题


Is it possible to put comments into Hibernate Query Language? If so, how?


回答1:


AFAIK, HQL does not support comments.




回答2:


Make sure your session is configured with:


<property name="hibernate.use_sql_comments">true</property>

Then do:


Query query = ...;
query.setComment("Some comment here");

and you will see something like the following in your MySQL log file (if you're using MySQL):


5998 Query /* Some comment here */ select .....




回答3:


If it helps your development, Hibernate Tools (Eclipse) supports double hyphens as single-line comments in their HQL editor. Helps me a lot. I've just tried the JPQL statement

SELECT pro --ro.id, cl.name, te.ordinalNbr, tt.code, se.startYear, pro.id, pcl.name, pte.ordinalNbr, ptt.code, pse.startYear
FROM Roster ro
  JOIN ro.season se
  JOIN ro.team te
  JOIN te.club cl
  JOIN te.teamType tt
  JOIN te.rosters pro
  JOIN pro.season pse
  JOIN pro.team pte
  JOIN pte.club pcl
  JOIN pte.teamType ptt
WHERE ro.id = 32
ORDER BY pse.startYear

and it returned the pro instances.

Also not quite to the point, but it might be useful nontheless.



来源:https://stackoverflow.com/questions/3196975/how-to-put-a-comment-into-hql-hibernate-query-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!