IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Wildfly/JBoss Java Discussion :

IllegalStateException:Illegal to call this method from injected,managed EntityManager


Sujet :

Wildfly/JBoss Java

  1. #1
    Membre du Club
    Inscrit en
    Mars 2005
    Messages
    100
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 100
    Points : 60
    Points
    60
    Par défaut IllegalStateException:Illegal to call this method from injected,managed EntityManager
    Salut,

    j'essaie d'exécuter mon session bean mais malhuersement je reçois l'erreur suivant :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
     
    javax.ejb.EJBTransactionRolledbackException: Illegal to call this method from injected, managed EntityManager
    	at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
    	at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
    	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:245)
    	at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
    	at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
    	at $Proxy165.onMessage(Unknown Source)
    	at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
    	at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:891)
    	at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
    	at org.jboss.mq.SpySession.run(SpySession.java:323)
    	at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:237)
    	at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
    	at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
    	at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
    	at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.IllegalStateException: Illegal to call this method from injected, managed EntityManager
    	at org.jboss.ejb3.entity.TransactionScopedEntityManager.getTransaction(TransactionScopedEntityManager.java:226)
    	at org.jboss.seam.persistence.EntityManagerProxy.getTransaction(EntityManagerProxy.java:110)
    	at 
    	...

    et voiçi comment est declaré mon bean :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
     
    @Stateless
    @TransactionManagement(TransactionManagementType.BEAN)
    @Name("monbean")
    public class MyFirstBean implements MonInterface{
    	@Logger
    	Log log;
     
    	@PersistenceContext
    	private EntityManager em;
     
     
    	public MyFirstBean () {
    	}
     
    	public void start(Message msg) { // methode de mon interface
    		try {
    			em.getTransaction().begin(); // erreur a ce niveau 
     
    			// ...mon traitement 
    		} catch (Exception e) {
    			log.error("Ooops! Exception", e);
    		} finally {
    			jbpmContext.close();
    			em.getTransaction().commit();
    		}
    	}
    }
    et finalement mon interface est la suivante:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    import javax.jms.Message;
     
    public interface MonInterface{
        public void start(Message msg);
    }

    je ne comprends pas pourquoi j'ai cet erreur?

    Merci

  2. #2
    Invité(e)
    Invité(e)
    Par défaut
    bonjour,

    petit déterrage mais j'ai exactement le même soucis

    une idée ?

    j'ai suivi les indications données dans le livre intitulé:
    Pro EJB3 Java Persistence API

    exemple du livre:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    em.getTransaction().begin();
    //traitement
    em.getTransaction().commit();
    j'effectue la même chose dans mon application:

    code de mon manager
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    ....
     
    @PersistenceContext(unitName="ToDoEJB3")
    	private EntityManager entityManager;
     
     
     
    	//Méthode CRUD
     
    	//CREATION
        public void create(int id, String nom, String prenom, String commentaire,Date date) {
        	entityManager.getTransaction().begin();
     
        	entityManager.persist(new Taches(id,nom,prenom,commentaire, date));
     
        	entityManager.getTransaction().rollback();
        	System.out.println("Tache créée");
        }
     
    ....
    notez que si j'enlève la partie transactionnelle tout fonctionne

    voici mon erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
     
    Exception in thread "main" javax.ejb.EJBException: java.lang.IllegalStateException: Illegal to call this method from injected, managed EntityManager
    	at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
    	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
    	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    	at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
    	at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
    	at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
    	at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
    	at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
    	at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
    	at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
    Caused by: java.lang.IllegalStateException: Illegal to call this method from injected, managed EntityManager
    	at org.jboss.ejb3.entity.TransactionScopedEntityManager.getTransaction(TransactionScopedEntityManager.java:226)
    	at bean.session.manager.TachesManager.create(TachesManager.java:31)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
    	at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
    	at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
    	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    	at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
    	at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
    	at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
    	at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
    	at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
    	at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
    	at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
    	at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:163)
    	at org.jboss.remoting.Client.invoke(Client.java:1634)
    	at org.jboss.remoting.Client.invoke(Client.java:548)
    	at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:67)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107)
    	at $Proxy0.create(Unknown Source)
    	at client.Client4.main(Client4.java:21)
    	at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:74)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:67)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107)
    	at $Proxy0.create(Unknown Source)
    	at client.Client4.main(Client4.java:21)
    quelqu'un à une idée ?

    merci

  3. #3
    Membre éclairé Avatar de XmasRock
    Inscrit en
    Janvier 2007
    Messages
    729
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 729
    Points : 821
    Points
    821
    Par défaut
    A mon avis, il doit y avoir une confusion, tu demandes une transaction a ton contexte alors que tu devrais te faire injecter une resource UserTransaction comme dans la spec chapitre 13.3.3 page 326 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    @Stateless
    @TransactionManagement(BEAN)
    public class MySessionBean implements MySession {
    @Resource javax.transaction.UserTransaction ut;
    @Resource javax.sql.DataSource database1;
    @Resource javax.sql.DataSource database2;
    public void someMethod(...) {
    java.sql.Connection con1;
    java.sql.Connection con2;
    java.sql.Statement stmt1;
    java.sql.Statement stmt2;
    // obtain con1 object and set it up for transactions
    con1 = database1.getConnection();
    stmt1 = con1.createStatement();
    // obtain con2 object and set it up for transactions
    con2 = database2.getConnection();
    stmt2 = con2.createStatement();
    //
    // Now do a transaction that involves con1 and con2.
    //
    // start the transaction
    ut.begin();
    // Do some updates to both co

  4. #4
    Invité(e)
    Invité(e)
    Par défaut
    Merci beaucoup, je vais y rejeter un oeil

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29
    Points : 28
    Points
    28
    Par défaut
    pour ceux qui buche sur le meme soucis:

    http://bigjavablog.blogspot.com/2008...llegal-to.html

    et faut faire ceci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    @Stateless
    @javax.ejb.ApplicationException(rollback = true)
    @TransactionManagement(TransactionManagementType.BEAN)
    @Remote
    public class TransfertDAOBean implements TransfertDAO {
     
    	@PersistenceContext(name = "titoumFluxJPA")
    	private EntityManager entityManager;
     
    	@Resource
    	private EJBContext context;
     
    .....
    .....
    UserTransaction ut = context.getUserTransaction();
     
    			ut.begin();
    			// We have an active transaction, we can access database use
    			// EntityManager intance.
    			Transferts myTxn = entityManager.find(Transferts.class, txn.getId());
     
    			myTxn.setStatus(txn.getStatus());
    			ut.commit();
    voili voilou

Discussions similaires

  1. [EJB3 Entity] Illegal to call this method from injected, managed EntityManager
    Par Invité(e) dans le forum Java EE
    Réponses: 3
    Dernier message: 19/01/2010, 17h43
  2. Call Remote EJB3 from Different Host
    Par ForHuman dans le forum NetBeans
    Réponses: 3
    Dernier message: 07/01/2009, 18h30
  3. Call stored procedure from trigger
    Par DAGADA dans le forum SQL
    Réponses: 3
    Dernier message: 24/05/2007, 13h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo