Package io.quarkus.hibernate.orm.panache
API usage
Hibernate with Panache comes in two flavors, the active record pattern viaPanacheEntity
and the repository pattern via PanacheRepository
.
To use the active record pattern, make your entities extend PanacheEntity
,
use public fields for your columns, use the existing operations defined as static methods on your entity class,
and define custom ones as static methods on your entity class:
@Entity
public class Person extends PanacheEntity {
public String name;
public LocalDate birth;
public PersonStatus status;
public static Person findByName(String name){
return find("name", name).firstResult();
}
public static List<Person> findAlive(){
return list("status", Status.Alive);
}
public static void deleteStefs(){
delete("name", "Stef");
}
}
To use the repository pattern, create a class implementing PanacheRepository
,
use the existing operations from your repository and define new ones on your repository class:
@ApplicationScoped
public class PersonRepository implements PanacheRepository<Person> {
public Person findByName(String name){
return find("name", name).firstResult();
}
public List<Person> findAlive(){
return list("status", Status.Alive);
}
public void deleteStefs(){
delete("name", "Stef");
}
}
Simplified queries
Normally, HQL queries are of this form: from EntityName [where ...] [order by ...]
, with optional elements
at the end.
If your select query does not start with from
, we support the following additional forms:
order by ...
which will expand tofrom EntityName order by ...
<singleColumnName>
(and single parameter) which will expand tofrom EntityName where <singleColumnName> = ?
<query>
will expand tofrom EntityName where <query>
update from
, we support the following additional forms:
from EntityName ...
which will expand toupdate from EntityName ...
set? <singleColumnName>
(and single parameter) which will expand toupdate from EntityName set <singleColumnName> = ?
set? <update-query>
will expand toupdate from EntityName set <update-query> = ?
delete from
, we support the following additional forms:
from EntityName ...
which will expand todelete from EntityName ...
<singleColumnName>
(and single parameter) which will expand todelete from EntityName where <singleColumnName> = ?
<query>
will expand todelete from EntityName where <query>
- Author:
- Stéphane Épardaud
-
Interface Summary Interface Description PanacheQuery<Entity> PanacheRepository<Entity> Represents a Repository for a specific type of entityEntity
, with an ID type ofLong
.PanacheRepositoryBase<Entity,Id> Represents a Repository for a specific type of entityEntity
, with an ID type ofId
. -
Class Summary Class Description Panache Utility class for Panache.PanacheEntity Represents an entity with a generated ID fieldPanacheEntity.id
of typeLong
.PanacheEntity_ PanacheEntityBase Represents an entity.