Hibernate 6.4 Fails to Convert Enum Types to snake_case in PostgreSQL CAST Operations

Hi everyone,

I’m using Hibernate 6.4 with PostgreSQL and the CamelCaseToUnderscoresNamingStrategy.

The issue is that while Hibernate correctly translates table and column names from camelCase to snake_case, it fails to do so for the PostgreSQL enum type name within CAST operations. This results in an SQL error because the database type doesn’t exist with the CamelCase name.
Simple Example:

  1. Java Enum:
public enum OrderStatus {
    PENDING,
    COMPLETED,
    CANCELLED;
}
  1. Entity:

@Entity
@Table(name = "product_orders")
public class ProductOrder {

    @Id
    private Long id;

    @JdbcType(PostgreSQLEnumJdbcType.class)
    @Enumerated(EnumType.STRING)
    @Column(name = "status", columnDefinition = "order_status")
    private OrderStatus status;

    // ... getters and setters
}
  1. The Problem:
    When I run a JPA query that filters by the enum status, Hibernate generates SQL that uses an incorrect type name in the PostgreSQL CAST syntax (::).

SQL Generated by Hibernate (Incorrect):
The CAST operation uses the Java enum’s class name (OrderStatus) instead of the actual database type name (order_status).
SQL

-- The WHERE clause is incorrect

select ... 
from product_orders o1_0 
where o1_0.status = 'PENDING'::OrderStatus

This fails with the PostgreSQL error, which lowercases unquoted type identifiers: ERROR: type “orderstatus” does not exist.

Expected SQL (Correct):
The naming strategy should also be applied to the type name in the CAST.
SQL

-- The WHERE clause should be
select ... 
from product_orders o1_0 
where o1_0.status = 'PENDING'::order_status

This version uses the correct enum type name (order_status) that actually exists in the database and would execute successfully.

My Environment:

Hibernate: 6.4
PostgreSQL: 12+
Naming Strategy: CamelCaseToUnderscoresNamingStrategy

Has anyone else encountered this? Is there a known workaround or a configuration I might be missing to make Hibernate respect the naming strategy for enum type casts in PostgreSQL?

Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.