Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class org.hibernate.mapping.BasicValue cannot be cast to class org.hibernate.mapping.ToOne while upgrading hibernate/JPA/Spring boot version to 3.1.1

Caused by: java.lang.ClassCastException: class org.hibernate.mapping.BasicValue cannot be cast to class org.hibernate.mapping.ToOne (org.hibernate.mapping.BasicValue and org.hibernate.mapping.ToOne are in unnamed module of loader 'app')

I was trying to upgrade spring-boot version to 3.1.1 and seeing this issue

like image 628
Kiran Avatar asked Sep 06 '25 08:09

Kiran


1 Answers

Encountered too during upgrade from SpringBoot 2.7 to 3.1 The problem turned out to be that there was a one-to-many relationship declaration (ToOne)

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "fieldInChildEntity")
    var children: MutableSet<ChildEntity> = mutableSetOf()
    

and the column was not of type of the corresponding ParentEntity, but rather a String (a BasicValue)

    @Column(name = "COLUMN_NAME")
    val fieldInChildEntity: String?,
    

It should have been:

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "FK", referencedColumnName = "PARENT_PK")
    var parent: ParentEntity?,
like image 116
N Sarj Avatar answered Sep 10 '25 00:09

N Sarj