10 Replies Latest reply on Nov 26, 2008 1:56 PM by Pedro Sena

    Bijection not working in test environment

    Pedro Sena Newbie

      Hi Guys,


      I'm having problems to configure my test environment, to make bijection work properly.


      Could someone help me with that?


      Here are my files:


      Components.xml:


      <persistence:managed-persistence-context name="global" auto-create="true"
                              scope="APPLICATION"
                       persistence-unit-jndi-name="java:/GlobalEntityManagerFactory"/>



      global-ds.xml:



      <datasources>
         
         <local-tx-datasource>
            <jndi-name>GlobalDS</jndi-name>
            <connection-url>jdbc:mysql://localhost:3306/travelne_global</connection-url>
            <driver-class>com.mysql.jdbc.Driver</driver-class>
            <user-name>root</user-name>
            <password></password>
         </local-tx-datasource>
          
      </datasources>



      The class(just a snippet) where the bijection is not occuring:



      @In
           private static EntityManager globalEntityManager;



      Is the static a problem for seam ?


      Any kind of help would be appreciated.


      Thanks in advance,


      Pedro Sena



        • 1. Re: Bijection not working in test environment
          Pedro Sena Newbie

          Ops, I forgot the persistence.xml



          <persistence-unit name="global">
                          <provider>org.hibernate.ejb.HibernatePersistence</provider>
                          <jta-data-source>java:/GlobalDS</jta-data-source>
                          <class> A couple of classes here... </class>
                          <properties>
                                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
                                  <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
                                  <property name="hibernate.connection.username" value="root" />
                                  <property name="hibernate.connection.password" value="" />
                                  <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/travelne_global" />
                                  <property name="hibernate.show_sql" value="true" />
                                  <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" />
                                  <property name="jboss.entity.manager.factory.jndi.name" value="java:/GlobalEntityManagerFactory"/>
                          </properties>
                  </persistence-unit>


          • 2. Re: Bijection not working in test environment
            Olivier Thierry Apprentice

            Did you try removing static keyword ?

            • 3. Re: Bijection not working in test environment
              ben abdallah Firas Newbie

              try this



              @PersistenceContext
              EntityManager em;
              
              



              • 4. Re: Bijection not working in test environment
                Pedro Sena Newbie

                Hi Guys,


                I tried to remove the static, it didn't work also.


                I tried the @PersistenceContext but also w/o success.


                One interesting thing is:


                In my test case, this assertion is true, it is not throwing an assertion error right here:


                assert getValue("#{entityManager}") != null;



                But in my class:


                @Name("MultiSchemaEntityManagerFactory")
                @Scope(ScopeType.SESSION)
                public class MultiSchemaEntityManagerFactory implements Serializable {
                
                     @In
                     private EntityManager entityManager;



                It is not working properly. I don't know if I missed something(I'm a seam newbie).


                So I would like any kind of help.


                Thanks,


                Pedro Sena


                • 5. Re: Bijection not working in test environment
                  Pedro Sena Newbie

                  For me, what appears to be happening is that my class is not being managed by seam.


                  Do I need to configure it in some other place ? I thought that just putting the @Name annotaion was enough, Do I need something else?


                  Thanks

                  • 6. Re: Bijection not working in test environment
                    Matt Nirgue Newbie

                    When JBoss starts, you should be able to see each component being initialized... You should see something like that :


                    ...
                    INFO  [Initialization] Installing components...
                    INFO  [Component] Component: yourComponent, scope: CONVERSATION, type: JAVA_BEAN, class: com.yourproject.YourComponent
                    ...



                    Look through your logs and try do find your component. If there's no trace of it in your log, then you can (almost) be sure that it's not managed by seam...

                    • 7. Re: Bijection not working in test environment
                      Pedro Sena Newbie

                      Matt Nirgue wrote on Nov 25, 2008 14:21:


                      When JBoss starts, you should be able to see each component being initialized... You should see something like that :

                      ...
                      INFO  [Initialization] Installing components...
                      INFO  [Component] Component: yourComponent, scope: CONVERSATION, type: JAVA_BEAN, class: com.yourproject.YourComponent
                      ...



                      Look through your logs and try do find your component. If there's no trace of it in your log, then you can (almost) be sure that it's not managed by seam...


                      Hi Matt,


                      Thanks a lot for your reply.


                      I'm using embedded jboss, I'm running my test using maven and, at least using maven inside eclipse, this log is not appearing.


                      So I suppose that my classe is not being managed by seam.


                      How to achive this ?


                      Is the @Name annotation not enough ?


                      I suppose that the problem may be in some XML file.


                      Thanks,


                      Pedro Sena

                      • 8. Re: Bijection not working in test environment
                        Matt Nirgue Newbie

                        I'm also using JBoss Embedded and Maven for my tests but I still see these logs... I think you should change your logging configuration  because the logs often provide useful information. In your case, it'd help you know for sure which components is initialized, etc.


                        I think it'd be easier to know what's wrong with your configuration... just my opinion though! :)

                        • 9. Re: Bijection not working in test environment
                          Pedro Sena Newbie

                          Matt Nirgue wrote on Nov 26, 2008 09:59:


                          I'm also using JBoss Embedded and Maven for my tests but I still see these logs... I think you should change your logging configuration  because the logs often provide useful information. In your case, it'd help you know for sure which components is initialized, etc.

                          I think it'd be easier to know what's wrong with your configuration... just my opinion though! :)


                          Hi Matt,


                          Nice tip :)


                          I changed my log4j.xml and now I'm seeing an interesting thing.


                          My component is being managed by Seam!!! I believe that the problem is the creation order, at least, in my log, my component is being created BEFORE the entityManager that i'm trying to inject to it.



                          INFO  [org.jboss.seam.Component] Component: MultiSchemaEntityManagerFactory, scope: SESSION, type: JAVA_BEAN, class: br.com.netsar.infra.repository.jpa.MultiSchemaEntityManagerFactory
                          INFO  [org.jboss.seam.Component] Component: entityManager, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.persistence.ManagedPersistenceContext
                          




                          My component is MultiSchemaEntityManagerFactory and I'm trying to inject an entityManager in this component.


                          I'll see how my component's precedence and as soon as I get a result I'll post here.


                          Thanks a lot for your info Matt,


                          Pedro Sena

                          • 10. Re: Bijection not working in test environment
                            Pedro Sena Newbie

                            LOL!!!


                            I'm REALLY a Seam newbie :(


                            I was expecting that, using the new operator, the atribute would be injected.


                            Now i'm using the correct, installed, version of my component and everything is working fine.


                            Thanks for all