[jboss-user] [JBoss Seam] - EntityManager Questions
Stateless Bean
do-not-reply at jboss.com
Mon Mar 19 19:40:22 EDT 2007
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.
and....
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>
| </component>
|
here is my persistence.xml:
| <persistence-unit name="Universum">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/MySqlDS</jta-data-source>
| <properties>
| <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" />
| </properties>
| </persistence-unit>
| </persistence>
|
and here i got problem:
What's the difference beetwen:
| @PersistenceContext(unitName="Universum")
| EntityManager em;
|
| @Resource (mappedName="java:/sguEntityManagerFactory")
| EntityManager em;
|
Should I also declare EntityManagerFactory in presistence.xml?
What's the difference beetwen:
| @PersistenceUnit
|
| @PersistenceContext
|
In some examples i see people do:
| EntityTransaction tx=em.getTransaction();
|
| try {
| tx.begin();
|
| // Do saves or modifications here
|
| tx.commit();
| } catch (Exception e) {
| if(tx.isActive()) tx.rollback();
| System.err.println("Error:"+e);
| } finally {
| em.close();
| }
|
and in some examples don't, for what is that? Is that mean that transaction is started?
Why when i use
| @PersistenceContext
| EntityManager em;
|
and do
| EntityTransaction tx=em.getTransaction();
|
i got following error:
"JTA EntityManager cannot access a transactions"
but if I do
| @PersistenceContext(unitName="Universum")
| protected EntityManager em;
|
I get "Illegal to call this method from injected, managed EntityManager"
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029554#4029554
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029554
More information about the jboss-user
mailing list