or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cdi-dependency-injection.mdconfiguration.mdcore-runtime.mddata-persistence.mdindex.mdreactive-programming.mdrest-web-services.mdscheduling.mdsecurity.mdtesting.md

data-persistence.mddocs/

0

# Data Persistence and ORM

1

2

Quarkus provides Hibernate ORM integration with Panache for simplified data access, transaction management, and support for both imperative and reactive database operations.

3

4

## Panache Entity Framework

5

6

### PanacheEntity Base Class

7

8

```java { .api }

9

public class PanacheEntity {

10

public void persist();

11

public void delete();

12

public static <T extends PanacheEntity> List<T> listAll();

13

public static <T extends PanacheEntity> T findById(Object id);

14

public static <T extends PanacheEntity> long count();

15

public static <T extends PanacheEntity> List<T> find(String query, Object... params);

16

public static <T extends PanacheEntity> T findFirst(String query, Object... params);

17

}

18

```

19

20

Base class providing active record pattern for entity persistence.

21

22

### PanacheRepository Interface

23

24

```java { .api }

25

public interface PanacheRepository<Entity> {

26

void persist(Entity entity);

27

void delete(Entity entity);

28

List<Entity> listAll();

29

Entity findById(Object id);

30

long count();

31

List<Entity> find(String query, Object... params);

32

}

33

```

34

35

Repository pattern interface for data access operations.

36

37

## Transaction Management

38

39

### @Transactional Annotation

40

41

```java { .api }

42

@Target({ElementType.TYPE, ElementType.METHOD})

43

@Retention(RetentionPolicy.RUNTIME)

44

public @interface Transactional {

45

TxType value() default TxType.REQUIRED;

46

Class[] rollbackOn() default {};

47

Class[] dontRollbackOn() default {};

48

}

49

```

50

51

Standard JTA transaction management annotation.

52

53

**Usage Example:**

54

```java

55

@Entity

56

public class User extends PanacheEntity {

57

public String name;

58

public String email;

59

}

60

61

@ApplicationScoped

62

public class UserService {

63

64

@Transactional

65

public User createUser(String name, String email) {

66

User user = new User();

67

user.name = name;

68

user.email = email;

69

user.persist();

70

return user;

71

}

72

}

73

```