Problems in InsertQuery Generation with Oracle Database

Team,
I am using Hibernate 5.2.12 and trying a simple entity insertion and retrieval in a database. The Entity Mapping uses a sequence generator of native type. The HBMXML file looks like this

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class entity-name="customer" lazy="true" name="customer" table="customer">
    <id name="CategoryID" type="int">
      <column name="CategoryID"/>
      <generator class="native"/>
    </id>
    <property name="name" type="string">
      <column name="name"/>
    </property>
    <property name="address" type="string">
      <column name="address"/>
    </property>
    <property name="DESCRIPTION" type="text">
      <column name="DESCRIPTION"/>
    </property>
  </class>
</hibernate-mapping>

I am trying this simple scenario of Inserting an Entity and then retrieving it back, however with this Entity XML, the same works in SQLServer Database but not in Oracle.

I checked the Queries that are generated and found out that the query for inserting the data in Oracle is missing.

Here are the Queries that are generated:

For SQLServer:

Hibernate:
drop table customer
Hibernate:
create table customer (
CategoryID int identity not null,
name varchar(255),
address varchar(255),
DESCRIPTION varchar(MAX),
primary key (CategoryID)
)
Hibernate:
insert
into
customer
(name, address, DESCRIPTION)
values
(?, ?, ?)
Hibernate:
select
customer0_.CategoryID as Category1_0_,
customer0_.name as name2_0_,
customer0_.address as address3_0_,
customer0_.DESCRIPTION as DESCRIPT4_0_
from
customer customer0_

For ORACLE :

Hibernate:
drop table customer cascade constraints
Hibernate:
drop sequence hibernate_sequence
Hibernate: create sequence hibernate_sequence start with 1 increment by 1
Hibernate:
create table customer (
CategoryID number(10,0) not null,
name varchar2(255),
address varchar2(255),
DESCRIPTION long,
primary key (CategoryID)
)
Hibernate:
select
hibernate_sequence.nextval
from
dual
Hibernate:
select
customer0_.CategoryID as CategoryID1_0_,
customer0_.name as name2_0_,
customer0_.address as address3_0_,
customer0_.DESCRIPTION as DESCRIPTION4_0_
from
customer customer0_

As we can see there is no Insert Query generated for Oracle Database, Can someone please let me know what i am missing here and how can i resolve this?

Thanks and Appreciate Your Help in Advance.

Did you try running entityManager.flush() after the persist operation yet? I guess you simply messed with the default flush mode or are simply not waiting for the commit to happen to observe the query being fired. The difference is, as you can see, that SQL Server uses an identity, so it has to eagerly insert the row to generate the id. Whereas for Oracle, you can see that a sequence value is fetched to serve as id for the object, yet the row insert for the object is deferred which allows Hibernate to do optimizations like batched inserts.

@beikov : I can get a sense of what you are talking about, however just for the sake of debugging, can you let me know which files should i debug for while attaching hibernate source code.

Or if there is another way around, please let me know and i would be glad to investigate deeply on this.

Thanks,
Ashudeep

There is nothing to debug, just call entityManager.flush() after persist and then you will see the insert statement being executed. Carefully read my last comment as that explains you everything you need to know about why you might not see the insert statement in your tests.