Class PanacheEntityBase

java.lang.Object
io.quarkus.hibernate.reactive.panache.PanacheEntityBase
Direct Known Subclasses:
PanacheEntity

public abstract class PanacheEntityBase extends Object

Represents an entity. If your Hibernate entities extend this class they gain auto-generated accessors to all their public fields (unless annotated with Transient), as well as a lot of useful methods. Unless you have a custom ID strategy, you should not extend this class directly but extend PanacheEntity instead.

Author:
Stéphane Épardaud
See Also:
  • Constructor Details

    • PanacheEntityBase

      public PanacheEntityBase()
  • Method Details

    • getSession

      public static io.smallrye.mutiny.Uni<org.hibernate.reactive.mutiny.Mutiny.Session> getSession()
      Returns the current Mutiny.Session
      Returns:
      the current Mutiny.Session
    • persist

      @CheckReturnValue public <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<T> persist()
      Persist this entity in the database, if not already persisted. This will set your ID field if it is not already set.
      Returns:
      See Also:
    • persistAndFlush

      @CheckReturnValue public <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<T> persistAndFlush()
      Persist this entity in the database, if not already persisted. This will set your ID field if it is not already set. Then flushes all pending changes to the database.
      Returns:
      See Also:
    • delete

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> delete()
      Delete this entity from the database, if it is already persisted.
      Returns:
      See Also:
    • isPersistent

      public boolean isPersistent()
      Returns true if this entity is persistent in the database. If yes, all modifications to its persistent fields will be automatically committed to the database at transaction commit time.
      Returns:
      true if this entity is persistent in the database.
    • flush

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> flush()
      Flushes all pending changes to the database.
      Returns:
    • findById

      @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<T> findById(Object id)
      Find an entity of this type by ID.
      Parameters:
      id - the ID of the entity to find.
      Returns:
      the entity found, or null if not found.
    • findById

      @CheckReturnValue @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<T> findById(Object id, jakarta.persistence.LockModeType lockModeType)
      Find an entity of this type by ID and lock it.
      Parameters:
      id - the ID of the entity to find.
      lockModeType - the locking strategy to be used when retrieving the entity.
      Returns:
      the entity found, or null if not found.
    • find

      @GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, Object... params)
      Find entities using a query, with optional indexed parameters.
      Parameters:
      query - a query string
      params - optional sequence of indexed parameters
      Returns:
      a new PanacheQuery instance for the given query
      See Also:
    • find

      @GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, io.quarkus.panache.common.Sort sort, Object... params)
      Find entities using a query and the given sort options, with optional indexed parameters.
      Parameters:
      query - a query string
      sort - the sort strategy to use
      params - optional sequence of indexed parameters
      Returns:
      a new PanacheQuery instance for the given query
      See Also:
    • find

      @GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, Map<String,Object> params)
      Find entities using a query, with named parameters.
      Parameters:
      query - a query string
      params - Map of named parameters
      Returns:
      a new PanacheQuery instance for the given query
      See Also:
    • find

      @GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, io.quarkus.panache.common.Sort sort, Map<String,Object> params)
      Find entities using a query and the given sort options, with named parameters.
      Parameters:
      query - a query string
      sort - the sort strategy to use
      params - Map of indexed parameters
      Returns:
      a new PanacheQuery instance for the given query
      See Also:
    • find

      @Deprecated(since="3.34") @GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, io.quarkus.panache.common.Parameters params)
      Deprecated.
      Find entities using a query, with named parameters.
      Parameters:
      query - a query string
      params - Parameters of named parameters
      Returns:
      a new PanacheQuery instance for the given query
      See Also:
    • find

      @Deprecated(since="3.34") @GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, io.quarkus.panache.common.Sort sort, io.quarkus.panache.common.Parameters params)
      Deprecated.
      Find entities using a query and the given sort options, with named parameters.
      Parameters:
      query - a query string
      sort - the sort strategy to use
      params - Parameters of indexed parameters
      Returns:
      a new PanacheQuery instance for the given query
      See Also:
    • findAll

      @GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> findAll()
      Find all entities of this type.
      Returns:
      a new PanacheQuery instance to find all entities of this type.
      See Also:
    • findAll

      @GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> findAll(io.quarkus.panache.common.Sort sort)
      Find all entities of this type, in the given order.
      Parameters:
      sort - the sort order to use
      Returns:
      a new PanacheQuery instance to find all entities of this type.
      See Also:
    • list

      @CheckReturnValue @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<List<T>> list(String query, Object... params)
      Find entities matching a query, with optional indexed parameters. This method is a shortcut for find(query, params).list().
      Parameters:
      query - a query string
      params - optional sequence of indexed parameters
      Returns:
      a List containing all results, without paging
      See Also:
    • list

      @CheckReturnValue @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<List<T>> list(String query, io.quarkus.panache.common.Sort sort, Object... params)
      Find entities matching a query and the given sort options, with optional indexed parameters. This method is a shortcut for find(query, sort, params).list().
      Parameters:
      query - a query string
      sort - the sort strategy to use
      params - optional sequence of indexed parameters
      Returns:
      a List containing all results, without paging
      See Also:
    • list

      @CheckReturnValue @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<List<T>> list(String query, Map<String,Object> params)
      Find entities matching a query, with named parameters. This method is a shortcut for find(query, params).list().
      Parameters:
      query - a query string
      params - Map of named parameters
      Returns:
      a List containing all results, without paging
      See Also:
    • list

      @CheckReturnValue @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<List<T>> list(String query, io.quarkus.panache.common.Sort sort, Map<String,Object> params)
      Find entities matching a query and the given sort options, with named parameters. This method is a shortcut for find(query, sort, params).list().
      Parameters:
      query - a query string
      sort - the sort strategy to use
      params - Map of indexed parameters
      Returns:
      a List containing all results, without paging
      See Also:
    • list

      @Deprecated(since="3.34") @CheckReturnValue @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<List<T>> list(String query, io.quarkus.panache.common.Parameters params)
      Deprecated.
      Find entities matching a query, with named parameters. This method is a shortcut for find(query, params).list().
      Parameters:
      query - a query string
      params - Parameters of named parameters
      Returns:
      a List containing all results, without paging
      See Also:
    • list

      @Deprecated(since="3.34") @CheckReturnValue @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<List<T>> list(String query, io.quarkus.panache.common.Sort sort, io.quarkus.panache.common.Parameters params)
      Deprecated.
      Find entities matching a query and the given sort options, with named parameters. This method is a shortcut for find(query, sort, params).list().
      Parameters:
      query - a query string
      sort - the sort strategy to use
      params - Parameters of indexed parameters
      Returns:
      a List containing all results, without paging
      See Also:
    • listAll

      @CheckReturnValue @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<List<T>> listAll()
      Find all entities of this type. This method is a shortcut for findAll().list().
      Returns:
      a List containing all results, without paging
      See Also:
    • listAll

      @CheckReturnValue @GenerateBridge public static <T extends PanacheEntityBase> io.smallrye.mutiny.Uni<List<T>> listAll(io.quarkus.panache.common.Sort sort)
      Find all entities of this type, in the given order. This method is a shortcut for findAll(sort).list().
      Parameters:
      sort - the sort order to use
      Returns:
      a List containing all results, without paging
      See Also:
    • count

      @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Long> count()
      Counts the number of this type of entity in the database.
      Returns:
      the number of this type of entity in the database.
      See Also:
    • count

      @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Long> count(String query, Object... params)
      Counts the number of this type of entity matching the given query, with optional indexed parameters.
      Parameters:
      query - a query string
      params - optional sequence of indexed parameters
      Returns:
      the number of entities counted.
      See Also:
    • count

      @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Long> count(String query, Map<String,Object> params)
      Counts the number of this type of entity matching the given query, with named parameters.
      Parameters:
      query - a query string
      params - Map of named parameters
      Returns:
      the number of entities counted.
      See Also:
    • count

      @Deprecated(since="3.34") @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Long> count(String query, io.quarkus.panache.common.Parameters params)
      Deprecated.
      Counts the number of this type of entity matching the given query, with named parameters.
      Parameters:
      query - a query string
      params - Parameters of named parameters
      Returns:
      the number of entities counted.
      See Also:
    • deleteAll

      @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Long> deleteAll()
      Delete all entities of this type from the database. WARNING: the default implementation of this method uses a bulk delete query and ignores cascading rules from the JPA model.
      Returns:
      the number of entities deleted.
      See Also:
    • deleteById

      @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Boolean> deleteById(Object id)
      Delete an entity of this type by ID.
      Parameters:
      id - the ID of the entity to delete.
      Returns:
      false if the entity was not deleted (not found).
    • delete

      @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Long> delete(String query, Object... params)
      Delete all entities of this type matching the given query, with optional indexed parameters. WARNING: the default implementation of this method uses a bulk delete query and ignores cascading rules from the JPA model.
      Parameters:
      query - a query string
      params - optional sequence of indexed parameters
      Returns:
      the number of entities deleted.
      See Also:
    • delete

      @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Long> delete(String query, Map<String,Object> params)
      Delete all entities of this type matching the given query, with named parameters. WARNING: the default implementation of this method uses a bulk delete query and ignores cascading rules from the JPA model.
      Parameters:
      query - a query string
      params - Map of named parameters
      Returns:
      the number of entities deleted.
      See Also:
    • delete

      @Deprecated(since="3.34") @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Long> delete(String query, io.quarkus.panache.common.Parameters params)
      Deprecated.
      Delete all entities of this type matching the given query, with named parameters. WARNING: the default implementation of this method uses a bulk delete query and ignores cascading rules from the JPA model.
      Parameters:
      query - a query string
      params - Parameters of named parameters
      Returns:
      the number of entities deleted.
      See Also:
    • persist

      @CheckReturnValue @GenerateBridge(callSuperMethod=true) public static io.smallrye.mutiny.Uni<Void> persist(Iterable<?> entities)
      Persist all given entities.
      Parameters:
      entities - the entities to persist
      Returns:
      See Also:
    • persist

      @CheckReturnValue @GenerateBridge(callSuperMethod=true) public static io.smallrye.mutiny.Uni<Void> persist(Stream<?> entities)
      Persist all given entities.
      Parameters:
      entities - the entities to persist
      Returns:
      See Also:
    • persist

      @CheckReturnValue @GenerateBridge(callSuperMethod=true) public static io.smallrye.mutiny.Uni<Void> persist(Object firstEntity, Object... entities)
      Persist all given entities.
      Parameters:
      entities - the entities to persist
      Returns:
      See Also:
    • update

      @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Integer> update(String query, Object... params)
      Update all entities of this type matching the given query, with optional indexed parameters.
      Parameters:
      query - a query string
      params - optional sequence of indexed parameters
      Returns:
      the number of entities updated.
      See Also:
    • update

      @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Integer> update(String query, Map<String,Object> params)
      Update all entities of this type matching the given query, with named parameters.
      Parameters:
      query - a query string
      params - Map of named parameters
      Returns:
      the number of entities updated.
      See Also:
    • update

      @Deprecated(since="3.34") @CheckReturnValue @GenerateBridge public static io.smallrye.mutiny.Uni<Integer> update(String query, io.quarkus.panache.common.Parameters params)
      Deprecated.
      Update all entities of this type matching the given query, with named parameters.
      Parameters:
      query - a query string
      params - Parameters of named parameters
      Returns:
      the number of entities updated.
      See Also: