ObjectDB ObjectDB

Entity factory



is it possible to create Entities with a custom factory? I want to create Entity instances via dependency injection like:

public class User {
    private final UserService userService;
    private User(UserService userService) {
        this.userService = userService;        

public interface EntityFactory {
    <T> T create(Class<T> entityClass);   

EntityManagerFactory entityManagerFactory = (...);

The JPA listeners are unsufficient since they are also created without the possibility to inject dependencies (at least without using static variables which are very bad code style). An alternative would be if one can create JPA listener instances inside his application and add this listener via API call to ObjectDB (like .

Is it possible to implement such a functionality? I think this would make a lot of people happier since Hibernate also offers such features.

Thanks and best wishes



Only standard Java EE / Spring Framework injection is supported.

If it may help, you can obtain the EntityManager in a JPA listener method by using JDO:

    EntityManager em = // find the EntityManager that manages this
ObjectDB Support

Thanks, I managed to use my own dependency injection method:

I store the current Context in a ThreadLocal and access it inside the new Entity to inject the dependencies.



To post on this website please sign in.