# NAMED\_ENUM failing validation/boot sequence (Hibernate 6.4)

**URL:** <https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088>\
**Category:** Hibernate ORM\
**Created:** [February 23, 2024, 8:23pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088 "2024-02-23T20:23:38Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![hdaws](https://avatars.discourse-cdn.com/v4/letter/h/7993a0/32.png) [@hdaws](https://discourse.hibernate.org/u/hdaws)\
**Post date:** [February 23, 2024, 8:23pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/1 "2024-02-23T20:23:38Z")

</div>

Using Spring Boot 3.2.2 and associated versions (Hibernate 6.4) on Postgres

I have the following java

```java
public enum AddressType{
	HOME,
	WORK,
	SCHOOL;
}

```

and used in an @Entity class

```java
	@Enumerated(EnumType.STRING)
	@JdbcTypeCode(SqlTypes.NAMED_ENUM)
	private AddressType type;

```

With the following sql schema

```sql
CREATE TYPE address_type AS ENUM('HOME','WORK','SCHOOL');

```

used in a normal table as

```sql
CREATE TABLE IF NOT EXISTS address (
                              id int8 NOT NULL,
                              create_date timestamp NULL,
                              postal_code text NULL,
                              street1 varchar(100) NULL,
                              street2 varchar(100) NULL,
                              country int8 NULL,
                              state int8 NULL,
                              **"type" address_type NULL,**
                              CONSTRAINT address_pkey PRIMARY KEY (id)
);

```

However, the schema cannot load and validate using this configuration with the following error:

`Schema-validation: wrong column type encountered in column [type] in table [address]; found ["address_type" (Types#VARCHAR)], but expecting [type (Types#NAMED_ENUM)]`

I cannot find any documentation indicating that there is an alternate way to declare the enumerator. If i keep `@Enumerated(EnumType.STRING)` and remove the JDBC Type annotation it does validate and boot but I haven’t tested to see if that really does what we want (and I’m inclined to believe it does not).

Using `@JdbcType(PostgreSQLEnumJdbcType.class)`. instead also gives me an identical error.

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![hdaws](https://avatars.discourse-cdn.com/v4/letter/h/7993a0/32.png) [@hdaws](https://discourse.hibernate.org/u/hdaws)\
**Post date:** [February 23, 2024, 8:25pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/2 "2024-02-23T20:25:53Z")

</div>

Well I would love to fix the formatting issue above, but I also get a 422 error on the forums attempting to do so.

---

<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:** [February 26, 2024, 9:25am UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/3 "2024-02-26T09:25:37Z")

</div>

Just remove the `@JdbcTypeCode` annotation. Using named enums is the default on PostgreSQL.

---

<div class="post-metadata">

**Author:** ![pedrobacchini](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pedrobacchini/32/3094_2.png) [@pedrobacchini](https://discourse.hibernate.org/u/pedrobacchini)\
**Post date:** [March 13, 2024, 7:48pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/4 "2024-03-13T19:48:02Z")

</div>

hello I tried this solution but without success I’m still getting the error:

Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [status] in table [table\_name]; found [table\_name\_status (Types#VARCHAR)], but expecting [investmentstatus (Types#NAMED\_ENUM)]

only when I use:

hibernate.ddl-auto: validate

When I don’t use it, I don’t get the error and everything works normally, could there be some adjustment to be made in the dialect?

I use:  
org.hibernate.dialect.PostgreSQLDialect

SpringBoot 3.2.1 Hibernate 6.4.1 on Postgres

---

<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:** [March 14, 2024, 9:23am UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/5 "2024-03-14T09:23:38Z")

</div>

Then try updating to the latest 6.4 release i.e. 6.4.4.Final

---

<div class="post-metadata">

**Author:** ![pedrobacchini](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pedrobacchini/32/3094_2.png) [@pedrobacchini](https://discourse.hibernate.org/u/pedrobacchini)\
**Post date:** [March 14, 2024, 1:20pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/6 "2024-03-14T13:20:31Z")

</div>

Same error, and my first time here on the hibernate forum, I’ll try to understand how to contribute to this error.

---

<div class="post-metadata">

**Author:** ![pedrobacchini](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pedrobacchini/32/3094_2.png) [@pedrobacchini](https://discourse.hibernate.org/u/pedrobacchini)\
**Post date:** [March 14, 2024, 2:40pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/7 "2024-03-14T14:40:15Z")

</div>

I created a repo to demonstrate the problem in main everything works normally

in the fix/not-work branch and where the problem is, it seems that the problem is using enum with an underlined name.

> **[GitHub - pedrobacchini/bug-jpa-enum-mapping-postgres at main](https://github.com/pedrobacchini/bug-jpa-enum-mapping-postgres/tree/main)**
>
> main

---

<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:** [March 14, 2024, 3:11pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/8 "2024-03-14T15:11:34Z")

</div>

The repository is not accessible. Either way, if you think you found a bug, please try to create a reproducer with our [test case template](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) 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.

---

<div class="post-metadata">

**Author:** ![pedrobacchini](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pedrobacchini/32/3094_2.png) [@pedrobacchini](https://discourse.hibernate.org/u/pedrobacchini)\
**Post date:** [March 14, 2024, 5:16pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/9 "2024-03-14T17:16:09Z")

</div>

I’m sorry, this is correct:

[https://github.com/pedrobachini/pedrobachini-bug-jpa-enum-mapping-postgres](https://github.com/pedrobachini/pedrobachini-bug-jpa-enum-mapping-postgres)

I will provide

---

<div class="post-metadata">

**Author:** ![pedrobacchini](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pedrobacchini/32/3094_2.png) [@pedrobacchini](https://discourse.hibernate.org/u/pedrobacchini)\
**Post date:** [March 14, 2024, 7:06pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/10 "2024-03-14T19:06:44Z")

</div>

> <https://github.com/hibernate/hibernate-test-case-templates/pull/374>

[https://hibernate.atlassian.net/browse/HHH-17849](https://hibernate.atlassian.net/browse/HHH-17849)

---

<div class="post-metadata">

**Author:** ![pedrobacchini](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pedrobacchini/32/3094_2.png) [@pedrobacchini](https://discourse.hibernate.org/u/pedrobacchini)\
**Post date:** [March 15, 2024, 1:32pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/11 "2024-03-15T13:32:48Z")

</div>

It was identified that it is not a bug but a new feature and I made the appropriate adjustment.

[https://hibernate.atlassian.net/browse/HHH-17855](https://hibernate.atlassian.net/browse/HHH-17855)

---

<div class="post-metadata">

**Author:** ![hdaws](https://avatars.discourse-cdn.com/v4/letter/h/7993a0/32.png) [@hdaws](https://discourse.hibernate.org/u/hdaws)\
**Post date:** [March 20, 2024, 5:16pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/12 "2024-03-20T17:16:37Z")

</div>

Worth noting, this got me past validation and then the second i tried to have the enumerators used, it failed.

I’ve unmarked this answer as a solution as the type issue persists. I suspect it’s related to the “not a bug but definitely not well documented” issue of naming schemes, but I’m not sure how to give hibernate any schema that it is happy with and actually uses the types correctly when issuing persist and merge commands.

---

<div class="post-metadata">

**Author:** ![pedrobacchini](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/pedrobacchini/32/3094_2.png) [@pedrobacchini](https://discourse.hibernate.org/u/pedrobacchini)\
**Post date:** [March 26, 2024, 12:36pm UTC](https://discourse.hibernate.org/t/named-enum-failing-validation-boot-sequence-hibernate-6-4/9088/13 "2024-03-26T12:36:13Z")

</div>

We found a solution:

it would be enough to define the columnDefinition

example:  
@Enumerated(EnumType.STRING)  
@Column(nullable = false, columnDefinition = “compose\_status”)  
@JdbcType(PostgreSQLEnumJdbcType.class)  
private ComposeStatus status;
