babyfish-ct / jimmer

A revolutionary ORM framework for both java and kotlin.
Apache License 2.0
876 stars 88 forks source link

[bug] ManyToMany collection is not associated after saving with VIOLENTLY_REPLACE #692

Closed belovaf closed 1 month ago

belovaf commented 1 month ago

Model:

@Entity
interface Store : SerialId {
    @ManyToMany(mappedBy = "stores")
    val books: List<Book>
}

@Entity
interface Book : SerialId {
    val name: String

    @ManyToMany
    val stores: List<Store>
}

Code:

sql.save(Store {
    id = 1
    books().addBy {
        name = "book"
    }
}) {
    setMode(SaveMode.UPDATE_ONLY)
    setAssociatedMode(Store::books, AssociatedSaveMode.VIOLENTLY_REPLACE)
}

Actual queries:

delete from BOOK_STORE_MAPPING where STORE_ID = ?, variables: [1], purpose: MUTATE
insert into BOOK(NAME) values(?), variables: {batch-0: [book]}, purpose: COMMAND

Missing insert into BOOK_STORE_MAPPING table.

babyfish-ct commented 1 month ago

See #694