获取条件查询的 JPQL/SQL 字符串表示

Getting the JPQL/SQL String Representations for a Criteria Query

如何使用 parmetervalue 获取条件查询的 SQL 字符串表示形式?

我试过了,但它 returns 对我来说是一个没有参数值的字符串:

String QueryString = 'SELECT * FROM CUSTOMERS WHERE lastname = ?'


query = entityManager.createNativeQuery(QueryString);

query.setParameter(1, "toto");

System.out.print(query.unwrap(JpaQuery.class).getDatabaseQuery().getSQLString());

但是returns"SELECT * FROM CUSTOMERS WHERE lastname = ?" 而不是 "SELECT * FROM CUSTOMERS WHERE lastname = 'toto'"

感谢@GrootC 帮我找到解决方案。

如果对其他人有帮助,这里是解决方案:

String QueryString = 'SELECT * FROM CUSTOMERS WHERE lastname = ?';
Query query = entityManager.createNativeQuery(QueryString); 
Session session = entityManager.unwrap(JpaEntityManager.class).getActiveSession();  
DatabaseQuery databaseQuery = query.unwrap(org.eclipse.persistence.jpa.JpaQuery.class).getDatabaseQuery();
DatabaseRecord recordWithValues= new DatabaseRecord();

query.setParameter(1, "toto"); 
recordWithValues.add(new DatabaseField(Integer.toString(1)), "toto");

databaseQuery.prepareCall(session, recordWithValues); 
String sqlStringWithArgs = databaseQuery.getTranslatedSQLString(session, recordWithValues);

System.out.print(sqlStringWithArgs);

====SELECT * FROM CUSTOMERS WHERE lastname = 'toto'====