1

我正在尝试连接到 Oracle,但我在 Hibernate-5.0 中遇到了这个错误,即使我在配置中启用了这个属性。

> Aug 10, 2015 8:49:34 AM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Aug 10, 2015 8:49:35 AM org.hibernate.AssertionFailure <init>
ERROR: HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: getGeneratedKeys() support is not enabled
Exception in thread "main" org.hibernate.AssertionFailure: getGeneratedKeys() support is not enabled
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.checkAutoGeneratedKeysSupportEnabled(StatementPreparerImpl.java:94)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:113)
    at org.hibernate.id.SequenceIdentityGenerator$Delegate.prepare(SequenceIdentityGenerator.java:93)

我的 hibernate.cfg.xml 如下。

<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="hibernate.connection.password">*****</property>
    <property name="hibernate.connection.url">jdbc:oracle:thin:@*****</property>
    <property name="hibernate.connection.username">*****</property>
    <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
    <property name="hibernate.jdbc.use_get_generated_keys">true</property>

    <property name="show_sql">true</property>
    <property name="connection.pool_size">1</property>
    <!-- List of XML mapping files -->
    <mapping resource="mapping/Employee.hbm.xml" />
</session-factory>

Employee.hbm.xml 如下所示

<hibernate-mapping>
<class name="domain.Employee" table="EMPLOYEE">
    <id name="id" type="integer" column="id">
        <generator class="sequence-identity">
            <param name="sequence">EMP_SEQ</param>
        </generator>
    </id>
    <property name="firstName" column="first_name" type="string" />
    <property name="lastName" column="last_name" type="string" />
    <property name="salary" column="salary" type="integer" />
</class>

我尝试了很多次,但似乎没有解决。我在这里哪里出错了?任何指针都是一个很大的帮助。提前致谢。

4

2 回答 2

1

不确定这是否是 Hibernate 版本的问题,因为当我在 POM 中将依赖项版本从 5.0.0.CR2 更改为 4.3.9.Final 时,它工作正常。

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.9.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.9.Final</version>
    </dependency>
于 2015-08-12T11:40:44.947 回答
0

我不认为问题出在您的代码上,而是 Oracle。

根据 Oracle9Dialect 中的评论,Oracle 不支持返回生成的密钥,不像任何其他数据库那样。

于 2015-08-10T20:17:32.443 回答