[jboss-user] [JBoss Seam] - @In EntityManager is null when create an object from named b
cftdanny
do-not-reply at jboss.com
Wed Aug 15 00:10:19 EDT 2007
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);
| }
| }
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() {
|
| @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();
| }
| }
Is there limited that we can not create a child bean from parent bean if child bean reference to parent bean?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4074265#4074265
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4074265
More information about the jboss-user
mailing list