-
1. Re: EntityManager newibe Question
mzeijen Aug 25, 2006 9:28 AM (in response to mrohad)Use the @PersistenceContext annotation.
Example:class SomePojo { @PersistenceContext private transient EntityManager entityManager; ..... }
I advice you to read the EJB3 documentation or take a look at the nice http://trailblazer.demo.jboss.com/EJB3Trail/ website.
Knowlage about EJB3 is really needed if you want to use Seam. -
2. Re: EntityManager newibe Question
c_eric_ray Aug 25, 2006 9:28 AM (in response to mrohad)Sounds like you should just have the EJB container inject it like so.
@PersistenceContext(unitName="your_persistence_unit") private EntityManager em;
The new EJB3 spec allows for container injection. I think they call it Inside Out Container (IOC) or something like that. Anyway, it's build on annotation from the 1.5 JDK. You can do quite a lot of this type of inject without seam. Seam builds on this concept and also introduces Outjection. -
3. Re: EntityManager newibe Question
mrohad Aug 25, 2006 9:55 AM (in response to mrohad)I tried that , I am getting null :(
it's not a session bean, just a pojo..
any other idea? -
4. Re: EntityManager newibe Question
mrohad Aug 25, 2006 10:04 AM (in response to mrohad)here are how I define the EM:
@PersistenceContext(unitName="globalEM") private transient EntityManager em;
here is xml<persistence> <persistence-unit name="globalEM"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/DefaultDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="validate"/> <property name="hibernate.show_sql" value="true"/> <!-- These are the default for JBoss EJB3, but not for HEM: --> <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/selectItemsEntityManagerFactory"/> <property name="jboss.entity.manager.jndi.name" value="java:/selectItemsEntityManager"/> </properties> </persistence-unit> </persistence>
I am getting null pointer exception
while using em.find(...) -
5. Re: EntityManager newibe Question
robjellinghaus Aug 25, 2006 7:02 PM (in response to mrohad)@PersistenceContext won't work unless your class is @Stateful or @Stateless, AFAIK.
Why are you not using a Seam component rather than a POJO? Seam's whole mission in life is managing your persistence context across multiple requests, conversations, sessions, etc. In similar cases in my app, I have Seam components that inject the EntityManager, and then I explicitly pass it into any POJOs that need it. This ensures I'm using the correctly scoped EntityManager for the current state of my Seam app.
Cheers,
Rob -
6. Re: EntityManager newibe Question
bfo81 Aug 26, 2006 6:22 AM (in response to mrohad)Seam's whole mission in life is managing your persistence context across multiple...
Wait? Do you want to say that the Seam Managed Persistence Context is the same for ALL components?
That would be a difference to @PersistenceContext(type=EXTENDED) as this one injects a unique PC for every bean. -
7. Re: EntityManager newibe Question
gavin.king Aug 28, 2006 5:09 PM (in response to mrohad)Use a JNDI lookup to get a container-managed EM, or use Component.getInstance() to get a Seam-managed EM.
-
8. Re: EntityManager newibe Question
mrohad Aug 29, 2006 12:47 AM (in response to mrohad)what are the differences between container managed and seam managed?
-
9. Re: EntityManager newibe Question
gavin.king Aug 29, 2006 1:10 PM (in response to mrohad)check the docs