2 Replies Latest reply on Jan 17, 2011 9:14 AM by djheisterberg

    JBossAS6 Scala dependency injection

    djheisterberg

      I'm having an issue with injection of EntityManagers, EJBs, etc. in scala code.  Thankfully it's easily reproducible in java, for example:

       

      public class DAO {

          @PersistenceContext

          private EntityManager em;

          ...

       

      This works just fine.  But in scala:

       

      class DAO {

          @PersistenceContext

          private var em: EntityManager = null

          ...

       

      fails with

       

      javax.ejb.EJBException: java.lang.IllegalArgumentException: failed to set value org.jboss.jpa.tx.TransactionScopedEntityManager@14aad613 with setter public javax.persistence.EntityManager DAO.em()

       

      You can reproduce this in the java code with

       

      public class DAO {

          @PersistenceContext

          private EntityManager em;

          public EntityManager em() {return em;}

          ...

       

       

      which is essentially what scala does.  It seems JBoss is getting confused and using setter injection rather than field -- you can verify the annotation is on the field.  Glassfish v3 works fine.  Is there some way to force JBoss to use field injection?