Closed fubai closed 1 year ago
@fubai Thanks for opening the issue, but it's not possible to figure out the problem without the mapping for those two entities: CourseLecturer
and the other one where this lecturer
is defined.
Especially the @Id
property in this entity where lecturer
is defined is important.
Here is those two entities:
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.OneToOne
import jakarta.persistence.Table
@Entity
@Table(name = "tb_course")
class Course(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null,
@Column(name = "name")
var name: String? = null,
) {
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "lecturer_id", referencedColumnName = "id")
var lecturer: CourseLecturer? = null
}
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Table
@Entity
@Table(name = "tb_course_lecturer")
class CourseLecturer(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null,
@Column(name = "name")
var name: String? = null,
)
We are using kotlin, and we use the all-open plugin to make all entities open:
<configuration>
<jvmTarget>${java.version}</jvmTarget>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>all-open</plugin>
<plugin>spring</plugin>
<plugin>no-arg</plugin>
<plugin>jpa</plugin>
</compilerPlugins>
<pluginOptions>
<option>all-open:annotation=jakarta.persistence.Entity</option>
<option>all-open:annotation=jakarta.persistence.MappedSuperclass</option>
<option>all-open:annotation=jakarta.persistence.Embeddable</option>
<option>no-arg:annotation=com.fz.annotations.NoArg</option>
</pluginOptions>
</configuration>
Thanks. I'll try to see if I can replicate it.
@fubai I managed to replicate the issue.
Fixed. I will release the 2.7.1 version next week.
@fubai The 2.7.1 version is released now, so you can try it out.
Great!
When I upgrade our project to SpringBoot 3.1.0,I got an exception here:
The hibernate version is:
6.2.2.Final
, and hypersistence-optimizer is2.7.0-jakarta
。The code below cause the exception, if i remove the mapping, the exception disappear.