-
1. Re: EntityManager is Null inside Constructor
blabno Jan 30, 2008 9:16 AM (in response to saeediqbal1)As far as I know, injection occurs after creation of object, so injected resources may not be used during construction. Make init() method and annotate it with @PostConstruct.
-
2. Re: EntityManager is Null inside Constructor
pmuir Feb 1, 2008 5:28 AM (in response to saeediqbal1)Are you injecting using @In or @PersistenceContext?
-
3. Re: EntityManager is Null inside Constructor
saeediqbal1 Feb 1, 2008 9:10 AM (in response to saeediqbal1)@PersistenceContext private EntityManager entityManager; private List<CorpCustomers> existingData; public void fillExistingData() { existingData = entityManager.createQuery("select c from CorpCustomers c where c.context = :con") .setParameter("con", "_574555XXXX") .getResultList(); }
and in the constructor i am trying to call this fillExistingData() method -
4. Re: EntityManager is Null inside Constructor
cyberanto Feb 1, 2008 1:17 PM (in response to saeediqbal1)do not initialize seam beans in the constructor; you will run into all kinds of troubles when you do this (I did :)
instead, use the annotation @PostConstruct for your fillExistingData() method -
5. Re: EntityManager is Null inside Constructor
cyberanto Feb 1, 2008 4:23 PM (in response to saeediqbal1)sorry for the repeat of information, didnt read blabno's post before
-
6. Re: EntityManager is Null inside Constructor
saeediqbal1 Feb 3, 2008 4:56 AM (in response to saeediqbal1)ok Thanks cyberanto
-
7. Re: EntityManager is Null inside Constructor
ericjava Feb 3, 2008 10:27 AM (in response to saeediqbal1)Yes, if you think about it, there's no way injection could occur before the constructor. There's no object to inject into!
In all my Seam managed components, the constructor does little or nothing beyond setting default values for some fields.
You can use the @Create annotation (I believe it is) to run some method after construction and injection have occureed.