Hibernate persistance.xml:由于连接为空而禁用上下文 LOB 创建

C_B*_*C_B 5 java xml hibernate jpa persistence.xml

我的persistence.xml

<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
  version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
  <persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>com.ibm.apiscanner.DTO.BaselineDTO</class>
    <properties>
      <property name="hibernate.connection.driver_class" value="com.ibm.db2.jcc.DB2Driver" />
      <property name="hibernate.connection.url"    value="jdbc:db2://localhost:{PORT}/{DB}" />
      <property name="hibernate.connection.username" value="{user}" />
      <property name="hibernate.connection.password" value="{password}" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
      <property name="show_sql" value="true"/>
      <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
    </properties>
  </persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)

我收到以下信息:

Jan 22, 2015 9:16:48 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.DB2Dialect
Jan 22, 2015 9:16:48 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Run Code Online (Sandbox Code Playgroud)

通过基本 JDBC 连接时,可以使用相同的 url、用户和密码组合。

有人有建议吗?

Vla*_*cea 3

这是一条 INFO 消息(无需担心),因为您设置了:

<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
Run Code Online (Sandbox Code Playgroud)

默认情况下,如果您不指定此属性,它将被设置为 true,并且将使用 JDBC 连接来检查数据库元数据。

所以你有两个选择:

  1. 您删除该属性
  2. 您保留它,但也添加此属性:

    hibernate.jdbc.lob.non_contextual_creation=true
    
    Run Code Online (Sandbox Code Playgroud)

    但随后您会收到其他一些信息消息,告诉您:

    HHH000421: Disabling contextual LOB creation as hibernate.jdbc.lob.non_contextual_creation is true
    
    Run Code Online (Sandbox Code Playgroud)