Skip to content

io microsphere hibernate entity EntityCallback

github-actions[bot] edited this page Jul 11, 2026 · 9 revisions

EntityCallback

Type: Interface | Module: microsphere-hibernate-core | Package: io.microsphere.hibernate.entity | Since: 1.0.0

Source: microsphere-hibernate-core/src/main/java/io/microsphere/hibernate/entity/EntityCallback.java

Overview

The lifecycle callback interface for entity. The implementation class will be loaded by ServiceLoader Java Services Loader.

Example Usage

{@code
  // Implement a custom EntityCallback registered via
  // META-INF/services/io.microsphere.hibernate.entity.EntityCallback
  public class LoggingEntityCallback implements EntityCallback {

### Declaration

```java
public interface EntityCallback
```

**Author:** Mercy

## Version Information

- **Introduced in:** `1.0.0`
- **Current Project Version:** `0.2.7-SNAPSHOT`

## Version Compatibility

This component is tested and compatible with the following Java versions:

| Java Version | Status |
|:---:|:---:|
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |

## Examples

```java
// Implement a custom EntityCallback registered via
  // META-INF/services/io.microsphere.hibernate.entity.EntityCallback
  public class LoggingEntityCallback implements EntityCallback {

      @Override
      public void onPersist(Object entity, String entityName) {
          System.out.println("Persisting: " + entityName + " -> " + entity);
      }

      @Override
      public void onLoad(Object id, String entityClassName, Object entity,
                         LockMode lockMode, boolean isAssociationFetch,
                         Object result, Boolean readOnly, LoadType loadType) {
          System.out.println("Loading: " + entityClassName + " id=" + id);
      }

      @Override
      public void onPreDelete(Object entity, Object id, Object[] state,
                              String[] propertyNames, Type[] types) {
          System.out.println("About to delete: " + entity);
      }
  }
```

## Usage

### Maven Dependency

Add the following dependency to your `pom.xml`:

```xml

    io.github.microsphere-projects
    microsphere-hibernate-core
    ${microsphere-hibernate.version}

```

> **Tip:** Use the BOM (`microsphere-hibernate-dependencies`) for consistent version management. See the [Getting Started](https://github.com/microsphere-projects/microsphere-hibernate#getting-started) guide.

### Import

```java
import io.microsphere.hibernate.entity.EntityCallback;
```

## See Also

- `LoadEventListener`
- `PersistEventListener`
- `MergeEventListener`
- `DeleteEventListener`
- `ReplicateEventListener`
- `FlushEntityEventListener`
- `EvictEventListener`
- `LockEventListener`
- `RefreshEventListener`
- `PreLoadEventListener`
- `PostLoadEventListener`
- `PreDeleteEventListener`
- `PostDeleteEventListener`
- `PreUpdateEventListener`
- `PostUpdateEventListener`
- `PreInsertEventListener`
- `PostInsertEventListener`
- `PreCollectionRecreateEventListener`
- `PostCollectionRecreateEventListener`
- `PreCollectionRemoveEventListener`
- `PostCollectionRemoveEventListener`
- `PreCollectionUpdateEventListener`
- `PostCollectionUpdateEventListener`
- `EventType`
- `Interceptor`

---

*This documentation was auto-generated from the source code of [microsphere-hibernate](https://github.com/microsphere-projects/microsphere-hibernate).*

Clone this wiki locally