Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

@MapsId works different after updating to reactive 3 #2338

Open
@majchrzw

Description

Hello after updating my code to hibernate reactive 3 I'm receiving this error in my code:
org.hibernate.exception.ConstraintViolationException: error executing SQL statement [ERROR: null value in column "book_id" of relation "book_description" violates not-null constraint (23502)] [insert into book_description (description,book_id,language) values (1,ドル2,ドル3ドル)]

My entites look like this:

@Entity
class Book(
 var name: String? = null
) {
 @Id
 @SequenceGenerator(name = "book_seq", sequenceName = "book_seq", allocationSize = 1)
 @GeneratedValue(strategy = SEQUENCE, generator = "book_seq")
 val id: Long? = null
 @OneToMany(mappedBy = "book", cascade = [PERSIST], fetch = LAZY, orphanRemoval = true)
 val descriptions: MutableSet<BookDescription> = mutableSetOf()
}
@Entity
class BookDescription(
 @EmbeddedId
 val id: BookDescriptionId,
 val description: String,
 @ManyToOne(fetch = FetchType.LAZY, cascade = [PERSIST])
 @MapsId("bookId")
 @JoinColumn(name = "book_id")
 var book: Book?
)
@Embeddable
class BookDescriptionId(
 val language: String,
) {
 var bookId: Long? = null
}

And I want to save them:

val book = Book(name = "name")
val description = BookDescription(id = BookDescriptionId(language = "EN"), description = "something", book = book)
book.descriptions.add(description)
sessionFactory.withTransaction { tx -> tx.persist(book) }

I've checked this issue and problem exists in hibernate reactive 3, but everything works fine in hibernate reactive 2 and hibernate 7.
The example code can be found here in 3 branches - https://github.com/majchrzw/mapsid-example.

I've already talked about this on zulipchat but without any real conclusion - https://hibernate.zulipchat.com/#narrow/channel/132096-hibernate-user/topic/.40MapsId.20in.20hibernate.207/with/527690393.

I'm not sure if this is intended behaviour or just a bug, but it stopped working after version update which is strange for me, as I cannot found any note on this in migration guide/release notes for reactive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /