HTE_ prefix added on default to database table names

Hi all,

I am facing the issue that Hibernate adds on default the prefix “HTE_” to all my assigned entities. My question is if there is a possible way to disable this or set another default prefix?

Example:
@Entity
@Table(name = “TEST_TABLE”)

the above table name results in HTE_TEST_TABLE when connecting to the Oracle database

I am using:
Java 19
Spring Boot version v3.0.1
Hibernate-core version 6.1.6.Final
Apache Maven version 3.8.6
Oracle Database 21c Express Edition for Windows x64

Thanks in advance!

1 Like

The HTE_ prefix is something that is prepended to temporary tables. These tables are created for certain multi-table mutation operations. Since Oracle has global temporary tables, these tables have to be created on startup upfront. You can create these tables yourself and then disable the automatic emitting of these create table DDLs, but you have to update to 6.2.0.CR1 for that, since the setting hibernate.hql.bulk_id_strategy.global_temporary.create_tables was only introduced as part of [HHH-15550] - Hibernate JIRA for 6.2.

1 Like

Hi, Is it mandatory to create these HTE_ prefix tables separately or during server startup? what will be the impact if we don’t create these temp tables? Please advise.

You can create the tables along with the rest of your schema. If you do multi-table mutation operations and the tables are not there, you will see a SQL error.

Hi, I also noticed the HTE_ prefix tables being created in my project after upgrading to hibernate 6.2 but I don’t have any multi-table entities. Are these tables still needed when I don’t use @Inheritance(strategy = InheritanceType.JOINED)?

If they are not needed, why are they created?

The HTE_ prefix is for tables to support multi-table insert statements, whereas the HT_ prefix is for tables to support multi-table update/delete statements.
I might be wrong, but I think that if you have an entity with a secondary table, this count’s as a multi-table entity and hence it will create HTE_ prefixed tables.
Please try to create a reproducer with our test case template (hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) and if you are able to reproduce the issue, create a bug ticket in our issue tracker(https://hibernate.atlassian.net) and attach that reproducer.

Hi @beikov, thanks for the quick answer. As suggested, I created a pull request with a test that fails if it detects that a HTE_* table was created. As you can see in my test, I simply created an Oracle test container and connected to it with a very simple entity.

Is this a bug? In my project we avoid @Inheritance(strategy = InheritanceType.JOINED), so would it make sense for us to disable the creation of the HTE_ tables via properties?

That’s indeed a bug, thanks for sharing that. Please create a Jira issue for this and we’ll see what we can do about this.

Thanks for confirming, here is the bug report: [HHH-17628] - Hibernate JIRA

For your information, this is not a bug, but a consequence of the entity using a sequence generator with an allocationSize that is greater than 1, which makes it impossible to do multi-row inserts with a single SQL statement and hence requires the use of temporary tables.

Thank you for the update that it is not a bug.

In the jira ticket, you state that, since the entity has an id sequence with increment > 1, the HTE_ table is created, even if it is not a multi-table entitiy. This is my case. Now I would like to understand if I would use the HTE_ tables in practice.

Are these tables exclusively used in HQL inserts like the example you gave?
insert into MySpecialEntity (attribute1) select e.data from OtherEntity e
Or are there other scenarios?

Thanks again!

Are these tables exclusively used in HQL inserts like the example you gave?

Yes, only in this case.

In the ticket [HHH-17628] - Hibernate JIRA , we have following statement

" I ran a quick test and was able to determine that the HTE_* temporary table creation in your case is triggered by the fact that your entity has a sequence-style generated id (@GeneratedValue(strategy = GenerationType.SEQUENCE)). This style of generators supports bulk-insertion, and this in-turn requires a multi-table insert strategy that uses temporary tables (on Oracle at least) as if there were multiple tables involved."

Where can I find some more information why GenerationType.SEQUENCE with allocationSize >1 requires "multi-table insert strategy ? Is this just some kind of optimization ? Or Am I missing something obvious ? In hibernate 5 HTE tables haven’t been required for such a case.

Hibernate ORM 5 didn’t support multi-table insert statements, so it didn’t have HTE tables.

I’m not using Inheritance on my entities
I just have @SequenceGenerator with allocationSize >1
Is there any easy way to avoid HTE tables ? beside setting allocationSize to 1 ?

I tried adding

  hibernate.query.mutation_strategy: org.hibernate.query.sqm.mutation.internal.inline.InlineMutationStrategy

but the tables are still being created by hibernate

I know I can add also

  hibernate.query.mutation_strategy.global_temporary.create_tables: false
  hibernate.query.mutation_strategy.global_temporary.drop_tables: false

but shouldn’t setting strategy as above be enough ? Or settings this stragegy does now work in this case, thats why the tables are still created ?

Multi-table inserts can also be necessary if you have secondary tables or join tables for one-to-one associations.

Why is this such a big problem that Hibernate tries to create these tables?

That’s because this is not a mutation strategy but rather an insert strategy. There is no inline variant for insert strategies.

Setting these config properties is the way to disable DDL generation for these tables, so that is what you need to do if you don’t want these tables.

Our DBAs does’t like when hibernate creates tables and creating couple hundreds of table manually is not fun. Also I just want to know all the options.

Which hibernate property control insert strategy ?
I’m guessing that those are Insert strategies
Screenshot 2024-06-07 at 14.05.45
Back to my main question:

Is there any easy way to avoid HTE tables ? beside setting allocationSize to 1 ?

Will Hibernate will fail when HTE tables are required but are missing on startup when “hibernate.ddl-auto=validate” ?

Read the documentation. We’re writing this stuff for a reason…

No it will not fail, but you can easily try this out yourself.