如果在代码片段后entity.getHistory()为null:
(getEntityManager()返回弹簧注入的EntityManager,数据库字段历史类型为:text或varchar2(2000)
Query query = getEntityManager().createNativeQuery("insert into table_name(..., history, ....) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
[...]
.setParameter(6, entity.getHistory())
[...]
query.executeUpdate();
Run Code Online (Sandbox Code Playgroud)
给出奇怪的例外:
17/11/11 06:26:09:009 [pool-2-thread-1] WARN util.JDBCExceptionReporter:100 - SQL Error: 0, SQLState: 42804
17/11/11 06:26:09:009 [pool-2-thread-1] ERROR util.JDBCExceptionReporter:101 - ERROR: **column "history" is of type text but expression is of type bytea**
Run Code Online (Sandbox Code Playgroud)
提示:您需要重写或转换表达式.
仅在此配置中出现问题:
操作系统:CentOS版本5.6(最终版)
Java:1.6.0_26
DB:PostgreSQL 8.1
JDBC驱动程序:postgresql-9.1-901.jdbc4
应用程序服务器:apache-tomcat-6.0.28
在其他一些配置或历史记录为空字符串时,一切正常.从pgAdmin执行的相同语句工作正常.
我想问题是在PostgreSQL JDBC驱动程序中,是否有一些明智的理由将空字符串视为bytea值?Postgres 8和9之间可能有一些奇怪的变化?
我使用JPA和Hibernate作为我的JPA提供者.我的应用程序需要连接到persistence.xml中定义的数据库(默认持久性单元)从表中获取多个已配置的系统,并为每个系统创建EntityManagerFactory(系统仅在连接参数,方言和驱动程序方面有所不同).
是否可以使用"模板"持久性单元?现在我正在为每个系统使用不同的复制持久性单元,但它似乎毫无意义.