PanacheRepository

Represents a Repository for a specific type of entity Entity, with an ID type of Long. Implementing this interface will gain you the exact same useful methods that are on PanacheEntity and PanacheCompanion. If you have a custom ID strategy, you should implement PanacheRepositoryBase instead.

Parameters

Entity

The type of entity to operate on

Functions

Link copied to clipboard
@GenerateBridge
open fun count(): Long

Counts the number of this type of entity in the database.

@GenerateBridge
open fun count(query: String, params: Parameters): Long
@GenerateBridge
open fun count(query: String, params: Map<String, Any>): Long

Counts the number of this type of entity matching the given query, with named parameters.

@GenerateBridge
open fun count(query: String, vararg params: Any): Long

Counts the number of this type of entity matching the given query, with optional indexed parameters.

Link copied to clipboard
open fun delete(entity: Entity)

Delete the given entity from the database, if it is already persisted.

@GenerateBridge
open fun delete(query: String, params: Parameters): Long
@GenerateBridge
open fun delete(query: String, params: Map<String, Any>): Long

Delete all entities of this type matching the given query, with named parameters.

@GenerateBridge
open fun delete(query: String, vararg params: Any): Long

Delete all entities of this type matching the given query, with optional indexed parameters.

Link copied to clipboard
@GenerateBridge
open fun deleteAll(): Long

Delete all entities of this type from the database.

Link copied to clipboard
@GenerateBridge
open fun deleteById(id: Long): Boolean

Delete an entity of this type by ID.

Link copied to clipboard
@GenerateBridge
open fun find(query: String, params: Parameters): PanacheQuery<Entity>
@GenerateBridge
open fun find(query: String, params: Map<String, Any>): PanacheQuery<Entity>

Find entities using a query, with named parameters.

@GenerateBridge
open fun find(query: String, vararg params: Any): PanacheQuery<Entity>

Find entities using a query, with optional indexed parameters.

@GenerateBridge
open fun find(query: String, sort: Sort, params: Parameters): PanacheQuery<Entity>
@GenerateBridge
open fun find(query: String, sort: Sort, params: Map<String, Any>): PanacheQuery<Entity>

Find entities using a query and the given sort options, with named parameters.

@GenerateBridge
open fun find(query: String, sort: Sort, vararg params: Any): PanacheQuery<Entity>

Find entities using a query and the given sort options, with optional indexed parameters.

Link copied to clipboard
@GenerateBridge
open fun findAll(): PanacheQuery<Entity>

Find all entities of this type.

@GenerateBridge
open fun findAll(sort: Sort): PanacheQuery<Entity>

Find all entities of this type, in the given order.

Link copied to clipboard
@GenerateBridge(targetReturnTypeErased = true)
open fun findById(id: Long): Entity?

Find an entity of this type by ID.

@GenerateBridge(targetReturnTypeErased = true)
open fun findById(id: Long, lockModeType: LockModeType): Entity?

Find an entity of this type by ID and lock it.

Link copied to clipboard
open fun flush()

Flushes all pending changes to the database using the EntityManager for the Entity entity class.

Link copied to clipboard
@GenerateBridge
open fun getEntityManager(): EntityManager

Returns the EntityManager for the Entity for extra operations (eg. CriteriaQueries)

Link copied to clipboard
open fun isPersistent(entity: Entity): Boolean

Returns true if the given 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.

Link copied to clipboard
@GenerateBridge
open fun list(query: String, params: Parameters): List<Entity>
@GenerateBridge
open fun list(query: String, params: Map<String, Any>): List<Entity>

Find entities matching a query, with named parameters. This method is a shortcut for find(query, params).list().

@GenerateBridge
open fun list(query: String, vararg params: Any): List<Entity>

Find entities matching a query, with optional indexed parameters. This method is a shortcut for find(query, params).list().

@GenerateBridge
open fun list(query: String, sort: Sort, params: Parameters): List<Entity>
@GenerateBridge
open fun list(query: String, sort: Sort, params: Map<String, Any>): List<Entity>

Find entities matching a query and the given sort options, with named parameters. This method is a shortcut for find(query, sort, params).list().

@GenerateBridge
open fun list(query: String, sort: Sort, vararg params: Any): List<Entity>

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().

Link copied to clipboard
@GenerateBridge
open fun listAll(): List<Entity>

Find all entities of this type. This method is a shortcut for findAll().list().

@GenerateBridge
open fun listAll(sort: Sort): List<Entity>

Find all entities of this type, in the given order. This method is a shortcut for findAll(sort).list().

Link copied to clipboard
open fun persist(entity: Entity)

Persist the given entity in the database, if not already persisted.

open fun persist(entities: Stream<Entity>)
open fun persist(entities: Iterable<Entity>)
open fun persist(firstEntity: Entity, vararg entities: Entity)

Persist all given entities.

Link copied to clipboard
open fun persistAndFlush(entity: Entity)

Persist the given entity in the database, if not already persisted. Then flushes all pending changes to the database.

Link copied to clipboard
@GenerateBridge
open fun stream(query: String, params: Parameters): Stream<Entity>
@GenerateBridge
open fun stream(query: String, params: Map<String, Any>): Stream<Entity>

Find entities matching a query, with named parameters. This method is a shortcut for find(query, params).stream(). It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.

@GenerateBridge
open fun stream(query: String, vararg params: Any): Stream<Entity>

Find entities matching a query, with optional indexed parameters. This method is a shortcut for find(query, params).stream(). It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.

@GenerateBridge
open fun stream(query: String, sort: Sort, params: Parameters): Stream<Entity>
@GenerateBridge
open fun stream(query: String, sort: Sort, params: Map<String, Any>): Stream<Entity>

Find entities matching a query and the given sort options, with named parameters. This method is a shortcut for find(query, sort, params).stream(). It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.

@GenerateBridge
open fun stream(query: String, sort: Sort, vararg params: Any): Stream<Entity>

Find entities matching a query and the given sort options, with optional indexed parameters. This method is a shortcut for find(query, sort, params).stream(). It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.

Link copied to clipboard
@GenerateBridge
open fun streamAll(): Stream<Entity>

Find all entities of this type. This method is a shortcut for findAll().stream(). It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.

@GenerateBridge
open fun streamAll(sort: Sort): Stream<Entity>

Find all entities of this type, in the given order. This method is a shortcut for findAll(sort).stream(). It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.

Link copied to clipboard
@GenerateBridge
open fun update(query: String, params: Parameters): Int
@GenerateBridge
open fun update(query: String, params: Map<String, Any>): Int

Update all entities of this type matching the given query, with named parameters.

@GenerateBridge
open fun update(query: String, vararg params: Any): Int

Update all entities of this type matching the given query, with optional indexed parameters.