简体   繁体   中英

How to not replace named parameters in EntityManager.createNativeQuery()?

I am using JBOSS AS 7 and I have to use this command prior to querying:

entityManager.createNativeQuery(
    "ALTER SESSION SET NLS_DATE_FORMAT =\"YYYY-MM-DD HH24:MI:SS\"");

Now if I fire up this query the error message "Not all named parameters have been set: [MI:SS]" is shown. That makes sense, and I understand named parameters and everything. But just in this case I want this whole string not fiddled with.

I also tried to set the "parameter" "MI" to MI and "SS" to SS, but that did not help either.

How can I fire this query up without Hibernate trying to replace the named parameters? Or how can I set this information globally in the application server resp. in the persistence.xml or the standalone.xml from JBOSS?

Try with single quotes:

String sql = "alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'";
entityManager.createNativeQuery(sql);

您是否尝试过这样的转义:

"alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM