-
1. Re: Use of EntityManager in Conversation Beans
cremersstijn Apr 16, 2008 4:34 PM (in response to charlscross)You can use the entitymanager with an @In annotation.
@In(create=true)
private EntityManager em;or
with an @PersistenceContext annotation, but i think that only works within an EJB
@PersistenceContext(type=PersistenceContextType.EXTENDED)
private EntityManager em; -
2. Re: Use of EntityManager in Conversation Beans
charlscross Apr 16, 2008 4:41 PM (in response to charlscross)Thank you, but I get the following:
@In attribute requires non-null value: conversador.em
Know why? -
3. Re: Use of EntityManager in Conversation Beans
cremersstijn Apr 16, 2008 4:50 PM (in response to charlscross)do you use (create=true) after the @In ?
-
4. Re: Use of EntityManager in Conversation Beans
charlscross Apr 16, 2008 4:53 PM (in response to charlscross)Yeah, the true is that I get the same error either if I use it or not. Maybe should I use something in components.xml or another xml file?
-
5. Re: Use of EntityManager in Conversation Beans
charlscross Apr 16, 2008 4:58 PM (in response to charlscross)For more info here is my Bean declaration:
@Name("conversador")
@Scope(ScopeType.CONVERSATION)
public class Conversador implements Serializable {
And my em declaration:
@In(create=true) private EntityManager em;
-
6. Re: Use of EntityManager in Conversation Beans
andygibson.contact.andygibson.net Apr 16, 2008 6:05 PM (in response to charlscross)In components.xml you should see something like :
<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/yourEntityManagerFactory" />
This ensures the entity manager is always automatically created.
-
7. Re: Use of EntityManager in Conversation Beans
charlscross Apr 16, 2008 6:23 PM (in response to charlscross)First of all thank you for your fast answers.
Yes, I've got it. I'm becoming crazy!
This is a test Conversation Bean I did for testing but I get the same error, maybe I'm missing something, I send to you because could be something trivial I'm missing.package com.eqt.maps;
import java.io.Serializable;
import javax.persistence.EntityManager;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
@Name("converser")
@Scope(ScopeType.CONVERSATION)
public class Converser implements Serializable {
@In(create=true,required=false)private EntityManager em;
private String cosa;
@Createpublic void begin(){
cosa = (String)em.createNativeQuery("select screenid from screens s where s.screenid=2").getSingleResult();
}public String getCosa() {
return cosa;
}
public void setCosa(String cosa) {
this.cosa = cosa;
}
} -
8. Re: Use of EntityManager in Conversation Beans
jchouinard Jun 18, 2008 9:26 PM (in response to charlscross)Well if this is still alive, from what I know you need to have the same name in your xml and bean
if your xml is :<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/yourEntityManagerFactory" />
you need your entity manager like this :
@In private EntityManager entityManager;