If there is a bean named database, which @In entity manager:
@Name("database") @AutoCreate public class Database { @In private EntityManager entityManager; public Table createTable() { return new Table(this); } public User getUser(Long id) { return this.entityManager.find(User.class, id); } }
public class Table { private Database database; public Table(Database database) { this.database = database; } public User getUser() { return this.database.getUser(0L); } }
public class Test() { @In private Database database; public void execute() { // The following code execute successfully Table t1 = new Table(this.database); User user1 = t1.getUser(); System.out.println(user1.toString()); // The following code will cause error // The entitymanager of database is null Table t2 = this.database.createTable(); User user2 = t2.getUser(); } }