0 Replies Latest reply on Aug 15, 2007 12:10 AM by Danny Chen

    @In EntityManager is null when create an object from named b

    Danny Chen Newbie

      If there is a bean named database, which @In entity manager:

      public class Database {
       private EntityManager entityManager;
       public Table createTable() {
       return new Table(this);
       public User getUser(Long id) {
       return this.entityManager.find(User.class, id);

      And a table (like DAO, just work with User table):
      public class Table {
       private Database database;
       public Table(Database database) {
       this.database = database;
       public User getUser() {
       return this.database.getUser(0L);

      If create table directly in bean, it will be ok, but if create table from Database, the entityManager in Database will be null. The following is test code:

      public class Test() {
       private Database database;
       public void execute() {
       // The following code execute successfully
       Table t1 = new Table(this.database);
       User user1 = t1.getUser();
       // The following code will cause error
       // The entitymanager of database is null
       Table t2 = this.database.createTable();
       User user2 = t2.getUser();

      Is there limited that we can not create a child bean from parent bean if child bean reference to parent bean?