-
- Notifications
You must be signed in to change notification settings - Fork 101
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.