简体   繁体   English

如何不替换EntityManager.createNativeQuery()中的命名参数?

[英]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: 我正在使用JBOSS AS 7,在查询之前必须使用以下命令:

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. 现在,如果我启动此查询,将显示错误消息“尚未设置所有命名参数:[MI:SS]”。 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. 我还尝试将“参数”“ MI”设置为MI,将“ SS”设置为SS,但这都没有帮助。

How can I fire this query up without Hibernate trying to replace the named parameters? 如何在没有Hibernate尝试替换命名参数的情况下启动此查询? Or how can I set this information globally in the application server resp. 或者,如何在应用程序服务器响应中全局设置此信息。 in the persistence.xml or the standalone.xml from JBOSS? 在JBOSS的persistence.xml或standalone.xml中?

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'"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 entityManager.createNativeQuery 不返回输入结果 - entityManager.createNativeQuery does not return a typed result HIBERNATE:TransactionRequiredException:在entityManager.createNativeQuery()之后执行更新/删除查询 - HIBERNATE : TransactionRequiredException: Executing an update/delete query after entityManager.createNativeQuery() 使用entityManager.createNativeQuery(query,foo.class) - use of entityManager.createNativeQuery(query,foo.class) EntityManager.createNativeQuery 在使用分页时返回对象列表而不是 BigDecimal 列表 - EntityManager.createNativeQuery returning list of objects instead of list of BigDecimal when using Pagination 实体管理器JPA的createNativeQuery出现setParameter问题 - setParameter issue with createNativeQuery of entityManager JPA 在 JPA EntityManager createNativeQuery 中实现分页 - Implementing pagination in JPA EntityManager createNativeQuery 如何使用 String 和 class 作为参数为 EntityManger createNativeQuery 编写 Junit 测试用例 - How to write Junit test cases for EntityManger createNativeQuery with String and class as parameters 我的单元测试出现问题 - Junit - mockito - EntityManager - createNativeQuery - Issue with my unit testing - Junit - mockito - EntityManager - createNativeQuery EntityManager createNativeQuery 在 Java Springboot 中返回错误的结果集 - EntityManager createNativeQuery returning wrong result set in Java Springboot 为什么EntityManager createNativeQuery列表有时返回BigDecimal而其他时候返回Integer? - Why EntityManager createNativeQuery lists sometimes return a BigDecimal and other times an Integer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM