命令行编译 Java

编译 Java

If you are using the Hibernate native API, then you need to use the Query#setComment method like this:

1
2
3
4
5
List<Person> persons = (List<Person>) session.createQuery(
"select p " +
"from Person p ")
.setComment( "t95=firstdraft" )
.list();

运行

If you are using JPA, then you can use a QueryHint:

1
2
3
4
5
List<Person> persons = entityManager.createQuery(
"select p " +
"from Person p ", Person.class)
.setHint( "org.hibernate.comment", "t95=firstdraft" )
.getResultList();

How to intercept and modify SQL queries with the Hibernate StatementInspector