# Problems in InsertQuery Generation with Oracle Database

**URL:** <https://discourse.hibernate.org/t/problems-in-insertquery-generation-with-oracle-database/5851>\
**Category:** Hibernate ORM\
**Created:** [November 19, 2021, 1:07pm UTC](https://discourse.hibernate.org/t/problems-in-insertquery-generation-with-oracle-database/5851 "2021-11-19T13:07:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashuspeed](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ashuspeed/32/1270_2.png) [@ashuspeed](https://discourse.hibernate.org/u/ashuspeed)\
**Post date:** [November 19, 2021, 1:07pm UTC](https://discourse.hibernate.org/t/problems-in-insertquery-generation-with-oracle-database/5851/1 "2021-11-19T13:07:32Z")

</div>

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

```auto
<?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.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [November 22, 2021, 10:29am UTC](https://discourse.hibernate.org/t/problems-in-insertquery-generation-with-oracle-database/5851/2 "2021-11-22T10:29:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ashuspeed](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ashuspeed/32/1270_2.png) [@ashuspeed](https://discourse.hibernate.org/u/ashuspeed)\
**Post date:** [November 23, 2021, 11:01am UTC](https://discourse.hibernate.org/t/problems-in-insertquery-generation-with-oracle-database/5851/3 "2021-11-23T11:01:50Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [November 23, 2021, 11:19am UTC](https://discourse.hibernate.org/t/problems-in-insertquery-generation-with-oracle-database/5851/4 "2021-11-23T11:19:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ashuspeed](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ashuspeed/32/1270_2.png) [@ashuspeed](https://discourse.hibernate.org/u/ashuspeed)\
**Post date:** [February 24, 2022, 10:33am UTC](https://discourse.hibernate.org/t/problems-in-insertquery-generation-with-oracle-database/5851/5 "2022-02-24T10:33:12Z")

</div>

Got it, Thanks @beikov , i invoked the flush function and after that it started working.
