This content has been marked as final.
Show 4 replies
-
1. Re: EntityManager in Destroy method
admin.admin.email.tld Sep 30, 2008 9:40 PM (in response to tszpinda)Are you injecting entityManager instance? are you using @PersistenceContext or @In (SMPC)?
If you are using SMPC, check components.xml to make sure the instance name matches exactly what you have in components.xml:
<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/foobarFactory"/>
So in this case, in your SFSB:
@In //inject the SHIMS persistence unit/context (SMPC) private EntityManager entityManager;
-
2. Re: EntityManager in Destroy method
bravocharlie.seam.signup.benny.me.uk Oct 1, 2008 12:59 PM (in response to tszpinda)How are you accessing entityManager?
You have @BypassInterceptors - so you'd need to use Component.getInstance(...)
-
3. Re: EntityManager in Destroy method
tszpinda Oct 1, 2008 10:07 PM (in response to tszpinda)Thanks for help I forgot to delete @BypassInterceptors, so now it looks like:
@Name("org.jboss.seam.security.identity") @Scope(value=ScopeType.SESSION) @Install(precedence = Install.APPLICATION) @Startup public class User extends RuleBasedIdentity { @In private EntityManager entityManager; @PreDestroy public void preDestroy() { log.info("Predestroy: " + getUsername()); Contact contact = ((Contact)Component.getInstance(Contact.class)); contact.setOnline(false); //why I have to have this here??? FullTextHibernateSessionProxy ep = ((FullTextHibernateSessionProxy)entityManager.getDelegate()); ep.merge(contact); ep.flush(); }
but if I do:
entityManager.merge(contact); entityManager.flush();
[Component] Exception calling JavaBean @PreDestroy method: org.jboss.seam.security.identity javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:301) at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:90) at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.flush(FullTextEntityManagerImpl.java:102) at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:90) at com.ylem.model.notstoreable.User.preDestroy(User.java:85)
Btw Im using SFSB, defined as below in componets.xml
<component name="org.jboss.seam.ui.EntityConverter"> <property name="entityManager">#{entityManager}</property> </component> <persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/webshopEntityManagerFactory" />
Thats odd for me, any help much appreciated!
-
4. Re: EntityManager in Destroy method
tszpinda Oct 2, 2008 10:56 AM (in response to tszpinda)Solved by @Transactional annotation:
@Transactional @PreDestroy public void preDestroy() { if (getUsername() != null) { log.info("Logged out: " + getUsername()); Contact contact = ((Contact) Component.getInstance(Contact.class)); if (contact != null) { contact.setOnline(false); entityManager.merge(contact); entityManager.flush(); } } }