Erwan Leroux (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6218b52...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNGUzMDk1ZTY1...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16375?atlOrigin=eyJpIjoiNGUzMD...
) HHH-16375 (
https://hibernate.atlassian.net/browse/HHH-16375?atlOrigin=eyJpIjoiNGUzMD...
) java.lang.ClassCastException when using @Enumerated(STRING) with length=1 on varchar
column (
https://hibernate.atlassian.net/browse/HHH-16375?atlOrigin=eyJpIjoiNGUzMD...
)
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Components: hibernate-core
Created: 26/Mar/2023 08:21 AM Environment: Tested on java 17 and Spring Boot 3.0.5
Priority: Major Reporter: Erwan Leroux (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6218b52...
)
After upgrading to Spring Boot 3 and Hibernate 6, I have a use case not working about an
enum :
@Column(name = "way", length = 1)
@Enumerated(EnumType.STRING)
private Way way;
// Forward(Aller in french), Backward(Retour in french)
public enum Way {A,R}
CREATE TABLE working
(
id VARCHAR PRIMARY KEY NOT NULL,
way VARCHAR(1)
);
It throws this exception :
Expecting code not to raise a throwable but caught
"org.springframework.transaction.TransactionSystemException: Could not commit JPA
transaction
...
at
fr.elendar.hibernate_enum_mvce.repository.EntityClassNotWorkingRepositoryTest.lambda$test_ko$0(EntityClassNotWorkingRepositoryTest.java:22)
at org.assertj.core.api.ThrowableAssert.catchThrowable(ThrowableAssert.java:63)
at
org.assertj.core.api.AssertionsForClassTypes.catchThrowable(AssertionsForClassTypes.java:892)
at
org.assertj.core.api.AssertionsForClassTypes.assertThatCode(AssertionsForClassTypes.java:863)
at org.assertj.core.api.Assertions.assertThatCode(Assertions.java:1287)
at
fr.elendar.hibernate_enum_mvce.repository.EntityClassNotWorkingRepositoryTest.test_ko(EntityClassNotWorkingRepositoryTest.java:18)
...
Caused by: jakarta.persistence.RollbackException: Error while committing the transaction
at
org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:83)
at
org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:104)
at
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:561)
... 104 more
Caused by: java.lang.ClassCastException: class java.lang. String cannot be cast to class
java.lang. Character (java.lang. String and java.lang. Character are in module java.base
of loader 'bootstrap' )
at
org.hibernate.type.descriptor.java.CharacterJavaType.unwrap(CharacterJavaType.java:20)
at org.hibernate.type.descriptor.jdbc.VarcharJdbcType$1.doBind(VarcharJdbcType.java:97)
at org.hibernate.type.descriptor.jdbc.BasicBinder.bind(BasicBinder.java:63)
...
... 105 more
I debugged it to this class and commit :
https://github.com/hibernate/hibernate-orm/commit/2f8f04747b5a4555836d5b7...
(
https://github.com/hibernate/hibernate-orm/commit/2f8f04747b5a4555836d5b7...
) and was told on Zulip Chat (
https://hibernate.zulipchat.com/#narrow/stream/132096-hibernate-user/topi...
) to create a bug here.
I made a reproducer here (
https://github.com/ErwanLeroux/hibernate_enum_mvce ) , the test
case in EntityClassNotWorkingRepositoryTest.java (
https://github.com/ErwanLeroux/hibernate_enum_mvce/blob/main/src/test/jav...
) is failling and show the exception.
I hope it’s enough, I tried to make a test case directly in hibernate-core and submit a
PR, but I lacked enough knownleged to make it work 🙂
(
https://hibernate.atlassian.net/browse/HHH-16375#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16375#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100219- sha1:ac3e918 )