getGeneratedKeys() support is not enabled error in Hibernate 5.0.0.CR2

1.4k views Asked by At

I'm trying to connect to Oracle and I'm getting this error in Hibernate-5.0 even though I have enabled this property in configuration.

> 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)

My hibernate.cfg.xml is as below.

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

And Employee.hbm.xml is like below

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

I have tried many times but not seem to resolve. Where I'm going wrong here? Any pointers is a great help. Thanks in advance.

2

There are 2 answers

0
Vishwa On BEST ANSWER

Not sure if this is an issue with the Hibernate version, because when I change the dependency version to 4.3.9.Final from 5.0.0.CR2 in POM then it is working fine.

    <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>
3
Peter On

I don't think it is your code that is the problem, but Oracle.

According to comments in the Oracle9Dialect, Oracle does not support returning the generated key, not like any other database does it.