Skip to content

Commit

Permalink
Panache EntityBase should flush on the right entity managerf
Browse files Browse the repository at this point in the history
Fixes #24394
  • Loading branch information
loicmathieu committed Mar 22, 2022
1 parent 5742fb0 commit 336550b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.quarkus.hibernate.orm.panache.kotlin

import io.quarkus.hibernate.orm.panache.common.runtime.AbstractJpaOperations
import io.quarkus.hibernate.orm.panache.common.runtime.AbstractJpaOperations.implementationInjectionMissing
import io.quarkus.hibernate.orm.panache.kotlin.runtime.KotlinJpaOperations.Companion.INSTANCE
import io.quarkus.panache.common.Parameters
import io.quarkus.panache.common.Sort
import io.quarkus.panache.common.impl.GenerateBridge
import java.lang.reflect.ParameterizedType
import java.util.stream.Stream
import javax.persistence.EntityManager
import javax.persistence.LockModeType
Expand Down Expand Up @@ -89,7 +89,8 @@ interface PanacheRepositoryBase<Entity : Any, Id: Any> {
* Flushes all pending changes to the database using the default EntityManager.
*/
fun flush() {
getEntityManager().flush()
val entityClass = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<*>
INSTANCE.getEntityManager(entityClass).flush()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.quarkus.hibernate.orm.panache.common.runtime.AbstractJpaOperations.implementationInjectionMissing;
import static io.quarkus.hibernate.orm.panache.runtime.JpaOperations.INSTANCE;

import java.lang.reflect.ParameterizedType;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -112,7 +113,8 @@ default boolean isPersistent(Entity entity) {
* FFlushes all pending changes to the database using the default EntityManager.
*/
default void flush() {
INSTANCE.getEntityManager().flush();
Class entityClass = ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
INSTANCE.getEntityManager(entityClass).flush();
}

// Queries
Expand Down

0 comments on commit 336550b

Please sign in to comment.