0 Replies Latest reply on Mar 19, 2007 7:40 PM by Stateless Bean

    EntityManager Questions

    Stateless Bean Novice

      First sorry for this topic here on Seam forum but EJB forum seams to be dead.
      I'm newbie in EJB3.0, and need help.
      Can anyone help me to configure well my EntityManager and answer for my questions?
      My target is to get EntityManager working with persistence.xml configuration.

      I read examples and still have problem.

      I want to also use Seam Realm, and declared in component.xml have declared em.

      <component name="em" auto-create="true" class="org.jboss.seam.core.ManagedPersistenceContext">
       <property name="persistenceUnitJndiName">java:/sguEntityManagerFactory</property>

      here is my persistence.xml:
      <persistence-unit name="Universum">
       <property name="dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
       <!-- <property name="hibernate.show_sql" value="true"/> -->
       <!-- <property name="hibernate.hbm2ddl.auto" value="create"/> -->
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/sguEntityManagerFactory" />

      and here i got problem:
      What's the difference beetwen:
      EntityManager em;
      @Resource (mappedName="java:/sguEntityManagerFactory")
      EntityManager em;

      Should I also declare EntityManagerFactory in presistence.xml?

      What's the difference beetwen:

      In some examples i see people do:
      EntityTransaction tx=em.getTransaction();
      try {
       // Do saves or modifications here
      } catch (Exception e) {
       if(tx.isActive()) tx.rollback();
      } finally {

      and in some examples don't, for what is that? Is that mean that transaction is started?

      Why when i use
      EntityManager em;

      and do
      EntityTransaction tx=em.getTransaction();

      i got following error:
      "JTA EntityManager cannot access a transactions"

      but if I do
      protected EntityManager em;

      I get "Illegal to call this method from injected, managed EntityManager"