-
1. Re: Component.getInstance() vs. injection
joblini Jul 31, 2009 2:05 AM (in response to asookazian)Hi Arbi,
Yes, cost of interceptors (@In) is a known issue, this is discussed by Dan Allen in his excellent article Speed up your Data-Driven JSF/Seam Application by Two Orders of Magnitude
For the problem you mention with SMPC, I usually just obtain the Entity manager directly, something like
Component.getInstance(EntityManager.class, true)
In addition, many of the Seam components have static instance() methods, which do the Component.getInstance() call for you, something like
Logger.instance()
-
2. Re: Component.getInstance() vs. injection
asookazian Jul 31, 2009 8:21 PM (in response to asookazian)with
Component.getInstance(EntityManager.class, true)
how would you know if the EntityManager instance manages a PC (@PersistenceContext) or SMPC (@In)?
-
3. Re: Component.getInstance() vs. injection
israel.bgf Jul 31, 2009 8:36 PM (in response to asookazian)Maybe i'm VERY wrong, but the @In/getInstance always will get the SMPC.
-
4. Re: Component.getInstance() vs. injection
asookazian Jul 31, 2009 11:07 PM (in response to asookazian)@In always injects SMPC (there's an @Unwrap getEntityManager() in ManagedPersistenceContext class).
Not sure about getInstance()...
I just tried this:
EntityManager entityManager = (EntityManager)Component.getInstance(EntityManager.class, true);
and got this:
Caused by: java.lang.IllegalArgumentException: No @Name annotation for class: javax.persistence.EntityManager at org.jboss.seam.Component.getComponentName(Component.java:1801)
plus for this:
<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/boBETSEntityManagerFactory"/>
I do not see setAutoCreate() or setName() methods in ManagedPersistenceContext class.
But I do see a clearDirty() method in ManagedPersistenceContext class but it seems that belongs in the EntityManager interface (but there's a clear() method in that API, not clearDirty()).
-
5. Re: Component.getInstance() vs. injection
swd847 Aug 1, 2009 4:09 AM (in response to asookazian)You have to do getInstance(
entityManager
). getInstance(Class) relies on an @Name annotation on the target class to determine the component name. Component.getInstance and injection will always return the same thing (a SMPC).name and autoCreate are availible on all seam components.
-
6. Re: Component.getInstance() vs. injection
tschleuss Oct 24, 2011 7:55 AM (in response to asookazian)How can i inject e component on seam 3,
likeComponent.getInstance
on seam 2 ?I'm confuse, i don't know how get component
and how i define a componente without a components.xmlThnaks!