Package io.quarkus.hibernate.orm.panache
Class PanacheEntityBase
- java.lang.Object
-
- io.quarkus.hibernate.orm.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 extendPanacheEntity
instead.- Author:
- Stéphane Épardaud
- See Also:
PanacheEntity
-
-
Constructor Summary
Constructors Constructor Description PanacheEntityBase()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static long
count()
Counts the number of this type of entity in the database.static long
count(String query, Parameters params)
Counts the number of this type of entity matching the given query, with named parameters.static long
count(String query, Object... params)
Counts the number of this type of entity matching the given query, with optional indexed parameters.static long
count(String query, Map<String,Object> params)
Counts the number of this type of entity matching the given query, with named parameters.void
delete()
Delete this entity from the database, if it is already persisted.static long
delete(String query, Parameters params)
Delete all entities of this type matching the given query, with named parameters.static long
delete(String query, Object... params)
Delete all entities of this type matching the given query, with optional indexed parameters.static long
delete(String query, Map<String,Object> params)
Delete all entities of this type matching the given query, with named parameters.static long
deleteAll()
Delete all entities of this type from the database.static boolean
deleteById(Object id)
Delete an entity of this type by ID.static <T extends PanacheEntityBase>
PanacheQuery<T>find(String query, Parameters params)
Find entities using a query, with named parameters.static <T extends PanacheEntityBase>
PanacheQuery<T>find(String query, Sort sort, Parameters params)
Find entities using a query and the given sort options, with named parameters.static <T extends PanacheEntityBase>
PanacheQuery<T>find(String query, Sort sort, Object... params)
Find entities using a query and the given sort options, with optional indexed parameters.static <T extends PanacheEntityBase>
PanacheQuery<T>find(String query, Sort sort, Map<String,Object> params)
Find entities using a query and the given sort options, with named parameters.static <T extends PanacheEntityBase>
PanacheQuery<T>find(String query, Object... params)
Find entities using a query, with optional indexed parameters.static <T extends PanacheEntityBase>
PanacheQuery<T>find(String query, Map<String,Object> params)
Find entities using a query, with named parameters.static <T extends PanacheEntityBase>
PanacheQuery<T>findAll()
Find all entities of this type.static <T extends PanacheEntityBase>
PanacheQuery<T>findAll(Sort sort)
Find all entities of this type, in the given order.static <T extends PanacheEntityBase>
TfindById(Object id)
Find an entity of this type by ID.static <T extends PanacheEntityBase>
TfindById(Object id, javax.persistence.LockModeType lockModeType)
Find an entity of this type by ID and lock it.static <T extends PanacheEntityBase>
Optional<T>findByIdOptional(Object id)
Find an entity of this type by ID.static <T extends PanacheEntityBase>
Optional<T>findByIdOptional(Object id, javax.persistence.LockModeType lockModeType)
Find an entity of this type by ID.static void
flush()
Flushes all pending changes to the database.static javax.persistence.EntityManager
getEntityManager()
Returns theEntityManager
for this entity class for extra operations (eg.boolean
isPersistent()
Returns true if this entity is persistent in the database.static <T extends PanacheEntityBase>
List<T>list(String query, Parameters params)
Find entities matching a query, with named parameters.static <T extends PanacheEntityBase>
List<T>list(String query, Sort sort, Parameters params)
Find entities matching a query and the given sort options, with named parameters.static <T extends PanacheEntityBase>
List<T>list(String query, Sort sort, Object... params)
Find entities matching a query and the given sort options, with optional indexed parameters.static <T extends PanacheEntityBase>
List<T>list(String query, Sort sort, Map<String,Object> params)
Find entities matching a query and the given sort options, with named parameters.static <T extends PanacheEntityBase>
List<T>list(String query, Object... params)
Find entities matching a query, with optional indexed parameters.static <T extends PanacheEntityBase>
List<T>list(String query, Map<String,Object> params)
Find entities matching a query, with named parameters.static <T extends PanacheEntityBase>
List<T>listAll()
Find all entities of this type.static <T extends PanacheEntityBase>
List<T>listAll(Sort sort)
Find all entities of this type, in the given order.void
persist()
Persist this entity in the database, if not already persisted.static void
persist(Iterable<?> entities)
Persist all given entities.static void
persist(Object firstEntity, Object... entities)
Persist all given entities.static void
persist(Stream<?> entities)
Persist all given entities.void
persistAndFlush()
Persist this entity in the database, if not already persisted.static <T extends PanacheEntityBase>
Stream<T>stream(String query, Parameters params)
Find entities matching a query, with named parameters.static <T extends PanacheEntityBase>
Stream<T>stream(String query, Sort sort, Parameters params)
Find entities matching a query and the given sort options, with named parameters.static <T extends PanacheEntityBase>
Stream<T>stream(String query, Sort sort, Object... params)
Find entities matching a query and the given sort options, with optional indexed parameters.static <T extends PanacheEntityBase>
Stream<T>stream(String query, Sort sort, Map<String,Object> params)
Find entities matching a query and the given sort options, with named parameters.static <T extends PanacheEntityBase>
Stream<T>stream(String query, Object... params)
Find entities matching a query, with optional indexed parameters.static <T extends PanacheEntityBase>
Stream<T>stream(String query, Map<String,Object> params)
Find entities matching a query, with named parameters.static <T extends PanacheEntityBase>
Stream<T>streamAll()
Find all entities of this type.static <T extends PanacheEntityBase>
Stream<T>streamAll(Sort sort)
Find all entities of this type, in the given order.static int
update(String query, Parameters params)
Update all entities of this type matching the given query, with named parameters.static int
update(String query, Object... params)
Update all entities of this type matching the given query, with optional indexed parameters.static int
update(String query, Map<String,Object> params)
Update all entities of this type matching the given query, with named parameters.
-
-
-
Method Detail
-
getEntityManager
@GenerateBridge public static javax.persistence.EntityManager getEntityManager()
Returns theEntityManager
for this entity class for extra operations (eg. CriteriaQueries)- Returns:
- the
EntityManager
for this entity class
-
persist
public void persist()
Persist this entity in the database, if not already persisted. This will set your ID field if it is not already set.
-
persistAndFlush
public void 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.
-
delete
public void delete()
Delete this entity from the database, if it is already persisted.
-
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
@GenerateBridge public static void flush()
Flushes all pending changes to the database.
-
findById
@GenerateBridge(targetReturnTypeErased=true) public static <T extends PanacheEntityBase> 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
@GenerateBridge(targetReturnTypeErased=true) public static <T extends PanacheEntityBase> T findById(Object id, javax.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.
-
findByIdOptional
@GenerateBridge public static <T extends PanacheEntityBase> Optional<T> findByIdOptional(Object id)
Find an entity of this type by ID.- Parameters:
id
- the ID of the entity to find.- Returns:
- if found, an optional containing the entity, else
Optional.empty()
.
-
findByIdOptional
@GenerateBridge public static <T extends PanacheEntityBase> Optional<T> findByIdOptional(Object id, javax.persistence.LockModeType lockModeType)
Find an entity of this type by ID.- Parameters:
id
- the ID of the entity to find.lockModeType
- the locking strategy to be used when retrieving the entity.- Returns:
- if found, an optional containing the entity, else
Optional.empty()
.
-
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
- aquery string
params
- optional sequence of indexed parameters- Returns:
- a new
PanacheQuery
instance for the given query - See Also:
find(String, Sort, Object...)
,find(String, Map)
,find(String, Parameters)
,list(String, Object...)
,stream(String, Object...)
-
find
@GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, Sort sort, Object... params)
Find entities using a query and the given sort options, with optional indexed parameters.- Parameters:
query
- aquery string
sort
- the sort strategy to useparams
- optional sequence of indexed parameters- Returns:
- a new
PanacheQuery
instance for the given query - See Also:
find(String, Object...)
,find(String, Sort, Map)
,find(String, Sort, Parameters)
,list(String, Sort, Object...)
,stream(String, Sort, Object...)
-
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
- aquery string
params
-Map
of named parameters- Returns:
- a new
PanacheQuery
instance for the given query - See Also:
find(String, Sort, Map)
,find(String, Object...)
,find(String, Parameters)
,list(String, Map)
,stream(String, Map)
-
find
@GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, Sort sort, Map<String,Object> params)
Find entities using a query and the given sort options, with named parameters.- Parameters:
query
- aquery string
sort
- the sort strategy to useparams
-Map
of indexed parameters- Returns:
- a new
PanacheQuery
instance for the given query - See Also:
find(String, Map)
,find(String, Sort, Object...)
,find(String, Sort, Parameters)
,list(String, Sort, Map)
,stream(String, Sort, Map)
-
find
@GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, Parameters params)
Find entities using a query, with named parameters.- Parameters:
query
- aquery string
params
-Parameters
of named parameters- Returns:
- a new
PanacheQuery
instance for the given query - See Also:
find(String, Sort, Parameters)
,find(String, Map)
,find(String, Parameters)
,list(String, Parameters)
,stream(String, Parameters)
-
find
@GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> find(String query, Sort sort, Parameters params)
Find entities using a query and the given sort options, with named parameters.- Parameters:
query
- aquery string
sort
- the sort strategy to useparams
-Parameters
of indexed parameters- Returns:
- a new
PanacheQuery
instance for the given query - See Also:
find(String, Parameters)
,find(String, Sort, Map)
,find(String, Sort, Parameters)
,list(String, Sort, Parameters)
,stream(String, Sort, Parameters)
-
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(Sort)
,listAll()
,streamAll()
-
findAll
@GenerateBridge public static <T extends PanacheEntityBase> PanacheQuery<T> findAll(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:
findAll()
,listAll(Sort)
,streamAll(Sort)
-
list
@GenerateBridge public static <T extends PanacheEntityBase> List<T> list(String query, Object... params)
Find entities matching a query, with optional indexed parameters. This method is a shortcut forfind(query, params).list()
.- Parameters:
query
- aquery string
params
- optional sequence of indexed parameters- Returns:
- a
List
containing all results, without paging - See Also:
list(String, Sort, Object...)
,list(String, Map)
,list(String, Parameters)
,find(String, Object...)
,stream(String, Object...)
-
list
@GenerateBridge public static <T extends PanacheEntityBase> List<T> list(String query, Sort sort, Object... params)
Find entities matching a query and the given sort options, with optional indexed parameters. This method is a shortcut forfind(query, sort, params).list()
.- Parameters:
query
- aquery string
sort
- the sort strategy to useparams
- optional sequence of indexed parameters- Returns:
- a
List
containing all results, without paging - See Also:
list(String, Object...)
,list(String, Sort, Map)
,list(String, Sort, Parameters)
,find(String, Sort, Object...)
,stream(String, Sort, Object...)
-
list
@GenerateBridge public static <T extends PanacheEntityBase> List<T> list(String query, Map<String,Object> params)
Find entities matching a query, with named parameters. This method is a shortcut forfind(query, params).list()
.- Parameters:
query
- aquery string
params
-Map
of named parameters- Returns:
- a
List
containing all results, without paging - See Also:
list(String, Sort, Map)
,list(String, Object...)
,list(String, Parameters)
,find(String, Map)
,stream(String, Map)
-
list
@GenerateBridge public static <T extends PanacheEntityBase> List<T> list(String query, Sort sort, Map<String,Object> params)
Find entities matching a query and the given sort options, with named parameters. This method is a shortcut forfind(query, sort, params).list()
.- Parameters:
query
- aquery string
sort
- the sort strategy to useparams
-Map
of indexed parameters- Returns:
- a
List
containing all results, without paging - See Also:
list(String, Map)
,list(String, Sort, Object...)
,list(String, Sort, Parameters)
,find(String, Sort, Map)
,stream(String, Sort, Map)
-
list
@GenerateBridge public static <T extends PanacheEntityBase> List<T> list(String query, Parameters params)
Find entities matching a query, with named parameters. This method is a shortcut forfind(query, params).list()
.- Parameters:
query
- aquery string
params
-Parameters
of named parameters- Returns:
- a
List
containing all results, without paging - See Also:
list(String, Sort, Parameters)
,list(String, Object...)
,list(String, Map)
,find(String, Parameters)
,stream(String, Parameters)
-
list
@GenerateBridge public static <T extends PanacheEntityBase> List<T> list(String query, Sort sort, Parameters params)
Find entities matching a query and the given sort options, with named parameters. This method is a shortcut forfind(query, sort, params).list()
.- Parameters:
query
- aquery string
sort
- the sort strategy to useparams
-Parameters
of indexed parameters- Returns:
- a
List
containing all results, without paging - See Also:
list(String, Parameters)
,list(String, Sort, Object...)
,list(String, Sort, Map)
,find(String, Sort, Parameters)
,stream(String, Sort, Parameters)
-
listAll
@GenerateBridge public static <T extends PanacheEntityBase> List<T> listAll()
Find all entities of this type. This method is a shortcut forfindAll().list()
.- Returns:
- a
List
containing all results, without paging - See Also:
listAll(Sort)
,findAll()
,streamAll()
-
listAll
@GenerateBridge public static <T extends PanacheEntityBase> List<T> listAll(Sort sort)
Find all entities of this type, in the given order. This method is a shortcut forfindAll(sort).list()
.- Parameters:
sort
- the sort order to use- Returns:
- a
List
containing all results, without paging - See Also:
listAll()
,findAll(Sort)
,streamAll(Sort)
-
stream
@GenerateBridge public static <T extends PanacheEntityBase> Stream<T> stream(String query, Object... params)
Find entities matching a query, with optional indexed parameters. This method is a shortcut forfind(query, params).stream()
. It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.- Parameters:
query
- aquery string
params
- optional sequence of indexed parameters- Returns:
- a
Stream
containing all results, without paging - See Also:
stream(String, Sort, Object...)
,stream(String, Map)
,stream(String, Parameters)
,find(String, Object...)
,list(String, Object...)
-
stream
@GenerateBridge public static <T extends PanacheEntityBase> Stream<T> stream(String query, Sort sort, Object... params)
Find entities matching a query and the given sort options, with optional indexed parameters. This method is a shortcut forfind(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.- Parameters:
query
- aquery string
sort
- the sort strategy to useparams
- optional sequence of indexed parameters- Returns:
- a
Stream
containing all results, without paging - See Also:
stream(String, Object...)
,stream(String, Sort, Map)
,stream(String, Sort, Parameters)
,find(String, Sort, Object...)
,list(String, Sort, Object...)
-
stream
@GenerateBridge public static <T extends PanacheEntityBase> Stream<T> stream(String query, Map<String,Object> params)
Find entities matching a query, with named parameters. This method is a shortcut forfind(query, params).stream()
. It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.- Parameters:
query
- aquery string
params
-Map
of named parameters- Returns:
- a
Stream
containing all results, without paging - See Also:
stream(String, Sort, Map)
,stream(String, Object...)
,stream(String, Parameters)
,find(String, Map)
,list(String, Map)
-
stream
@GenerateBridge public static <T extends PanacheEntityBase> Stream<T> stream(String query, Sort sort, Map<String,Object> params)
Find entities matching a query and the given sort options, with named parameters. This method is a shortcut forfind(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.- Parameters:
query
- aquery string
sort
- the sort strategy to useparams
-Map
of indexed parameters- Returns:
- a
Stream
containing all results, without paging - See Also:
stream(String, Map)
,stream(String, Sort, Object...)
,stream(String, Sort, Parameters)
,find(String, Sort, Map)
,list(String, Sort, Map)
-
stream
@GenerateBridge public static <T extends PanacheEntityBase> Stream<T> stream(String query, Parameters params)
Find entities matching a query, with named parameters. This method is a shortcut forfind(query, params).stream()
. It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.- Parameters:
query
- aquery string
params
-Parameters
of named parameters- Returns:
- a
Stream
containing all results, without paging - See Also:
stream(String, Sort, Parameters)
,stream(String, Object...)
,stream(String, Map)
,find(String, Parameters)
,list(String, Parameters)
-
stream
@GenerateBridge public static <T extends PanacheEntityBase> Stream<T> stream(String query, Sort sort, Parameters params)
Find entities matching a query and the given sort options, with named parameters. This method is a shortcut forfind(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.- Parameters:
query
- aquery string
sort
- the sort strategy to useparams
-Parameters
of indexed parameters- Returns:
- a
Stream
containing all results, without paging - See Also:
stream(String, Parameters)
,stream(String, Sort, Object...)
,stream(String, Sort, Map)
,find(String, Sort, Parameters)
,list(String, Sort, Parameters)
-
streamAll
@GenerateBridge public static <T extends PanacheEntityBase> Stream<T> streamAll()
Find all entities of this type. This method is a shortcut forfindAll().stream()
. It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.- Returns:
- a
Stream
containing all results, without paging - See Also:
streamAll(Sort)
,findAll()
,listAll()
-
streamAll
@GenerateBridge public static <T extends PanacheEntityBase> Stream<T> streamAll(Sort sort)
Find all entities of this type, in the given order. This method is a shortcut forfindAll(sort).stream()
. It requires a transaction to work. Without a transaction, the underlying cursor can be closed before the end of the stream.- Parameters:
sort
- the sort order to use- Returns:
- a
Stream
containing all results, without paging - See Also:
streamAll()
,findAll(Sort)
,listAll(Sort)
-
count
@GenerateBridge public static 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(String, Object...)
,count(String, Map)
,count(String, Parameters)
-
count
@GenerateBridge public static long count(String query, Object... params)
Counts the number of this type of entity matching the given query, with optional indexed parameters.- Parameters:
query
- aquery string
params
- optional sequence of indexed parameters- Returns:
- the number of entities counted.
- See Also:
count()
,count(String, Map)
,count(String, Parameters)
-
count
@GenerateBridge public static 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
- aquery string
params
-Map
of named parameters- Returns:
- the number of entities counted.
- See Also:
count()
,count(String, Object...)
,count(String, Parameters)
-
count
@GenerateBridge public static long count(String query, Parameters params)
Counts the number of this type of entity matching the given query, with named parameters.- Parameters:
query
- aquery string
params
-Parameters
of named parameters- Returns:
- the number of entities counted.
- See Also:
count()
,count(String, Object...)
,count(String, Map)
-
deleteAll
@GenerateBridge public static 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:
delete(String, Object...)
,delete(String, Map)
,delete(String, Parameters)
-
deleteById
@GenerateBridge public static 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
@GenerateBridge public static 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
- aquery string
params
- optional sequence of indexed parameters- Returns:
- the number of entities deleted.
- See Also:
deleteAll()
,delete(String, Map)
,delete(String, Parameters)
-
delete
@GenerateBridge public static 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
- aquery string
params
-Map
of named parameters- Returns:
- the number of entities deleted.
- See Also:
deleteAll()
,delete(String, Object...)
,delete(String, Parameters)
-
delete
@GenerateBridge public static long delete(String query, Parameters 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
- aquery string
params
-Parameters
of named parameters- Returns:
- the number of entities deleted.
- See Also:
deleteAll()
,delete(String, Object...)
,delete(String, Map)
-
persist
@GenerateBridge(callSuperMethod=true) public static void persist(Iterable<?> entities)
Persist all given entities.- Parameters:
entities
- the entities to persist- See Also:
persist()
,persist(Stream)
,persist(Object,Object...)
-
persist
@GenerateBridge(callSuperMethod=true) public static void persist(Stream<?> entities)
Persist all given entities.- Parameters:
entities
- the entities to persist- See Also:
persist()
,persist(Iterable)
,persist(Object,Object...)
-
persist
@GenerateBridge(callSuperMethod=true) public static void persist(Object firstEntity, Object... entities)
Persist all given entities.- Parameters:
entities
- the entities to persist- See Also:
persist()
,persist(Stream)
,persist(Iterable)
-
update
@GenerateBridge public static int update(String query, Object... params)
Update all entities of this type matching the given query, with optional indexed parameters.- Parameters:
query
- aquery string
params
- optional sequence of indexed parameters- Returns:
- the number of entities updated.
- See Also:
update(String, Map)
,update(String, Parameters)
-
update
@GenerateBridge public static int update(String query, Map<String,Object> params)
Update all entities of this type matching the given query, with named parameters.- Parameters:
query
- aquery string
params
-Map
of named parameters- Returns:
- the number of entities updated.
- See Also:
update(String, Object...)
,update(String, Parameters)
-
update
@GenerateBridge public static int update(String query, Parameters params)
Update all entities of this type matching the given query, with named parameters.- Parameters:
query
- aquery string
params
-Parameters
of named parameters- Returns:
- the number of entities updated.
- See Also:
update(String, Object...)
,update(String, Map)
-
-