5 Replies Latest reply on May 19, 2014 11:25 AM by casta_oh

    Cannot populate table with Arquillian Persistence yml when jpa has table and Schema

    casta_oh

      Hi all.

       

      I have one JPA like this:

       

      @Entity
      @Table(name="CATE_MVTO_PERSONA", schema="JPA_PART_ORAPOS")
      @NamedQueries({
        @NamedQuery(name = CateMvtoPersonaJPA.FIND_BY_ID, query = "SELECT o FROM CateMvtoPersonaJPA o WHERE o.id.persona = :persona AND o.id.identMov = :identMov"),
        @NamedQuery(name = CateMvtoPersonaJPA.FIND, query = "SELECT o FROM CateMvtoPersonaJPA o WHERE o.id.persona = :persona")
      })
      

       

      As you can see, due to business requirements I must have the name of the schema in the jpa, not in the persistence.xml.

       

      I want to test my EJB managing this JPA with Entity Persistence. To do this, I use arquillian persistence to populate the table CATE_MVTO_PERSONA with a file yml like this:

       

      CATE_MVTO_PERSONA:
        - PERSONA: "123456"
          IDENT_MOV: "identificador1"
          ID_CATEGORIA: "121212"
          IND_HABILITADO: "N"   
      

       

      I have managed to populate the table if my jpa doesn`t have the annotation schema, but I need to populate the table with the schema name in the JPA.

       

      I have googled a lot searching a possible solution for this, but no luck finding a solution.

       

      Please, may somebody help me telling me how to do this?

       

      I have already tried:

       

      JPA_PART_ORAPOS.CATE_MVTO_PERSONA:
        - PERSONA: "123456"
          IDENT_MOV: "identificador1"
          ID_CATEGORIA: "121212"
          IND_HABILITADO: "N"   
      

       

      With no luck.

       

      This is my persistence.xml:

       

      <persistence-unit name="ebkextracto_categorias_pu" transaction-type="JTA">
              <jta-data-source>jdbc/arquillian</jta-data-source>
              <class>com.gneis.ebkextracto.jpa.CateClaveConceptoJPA</class>
              <class>com.gneis.ebkextracto.jpa.CateConceptoPersJPA</class>
              <class>com.gneis.ebkextracto.jpa.CateConceptoPersJPAPK</class>
              <class>com.gneis.ebkextracto.jpa.CateConPersonalizadoJPA</class>
              <class>com.gneis.ebkextracto.jpa.CateConPersonalizadoJPAPK</class>
              <class>com.gneis.ebkextracto.jpa.CateDesPersonaJPA</class>
              <class>com.gneis.ebkextracto.jpa.CateDesPersonaJPAPK</class>
              <class>com.gneis.ebkextracto.jpa.CateMvtoPersonaJPA</class>
              <class>com.gneis.ebkextracto.jpa.CateMvtoPersonaJPAPK</class>
              <class>com.gneis.ebkextracto.jpa.Game</class>
              <properties>
                  <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
                  <property name="eclipselink.logging.level.sql" value="FINE"/>
                  <property name="eclipselink.logging.parameters" value="true"/>
              </properties>
          </persistence-unit>
      

       

      Arquillian creates the datasource. The problem is evolved in yml + schema JPA.

       

      Maybe I can use xml or a sql query?

       

      Regards

        • 1. Re: Cannot populate table with Arquillian Persistence yml when jpa has table and Schema
          kwintesencja

          Hi there,

           

          have you tried to configure schema in arquillian.xml?

           

              <extension qualifier="persistence-dbunit">

                <property name="schema">sa</property>

            </extension>



          I hope it helps

          1 of 1 people found this helpful
          • 2. Re: Cannot populate table with Arquillian Persistence yml when jpa has table and Schema
            bmajsak

            Rafael Pestano, many thanks for stepping in. That was exactly my response, you can try this workaround which has certain limitation - can only work with one schema at the moment.

             

            Juan Casta, please file feature request in JIRA and I will take care of it.

             

            Cheers,

            Bartosz

            • 3. Re: Cannot populate table with Arquillian Persistence yml when jpa has table and Schema
              casta_oh

              Hi.

               

              Thanks @Rafael Pestano and @Bartosz Majsak.

               

              I did not try your solution. As soon as I can I will check it and I will inform you.

               

              Regards.

              • 4. Re: Re: Cannot populate table with Arquillian Persistence yml when jpa has table and Schema
                casta_oh

                Hello.

                 

                I have tried next things:

                 

                <extension qualifier="persistence-dbunit">

                        <property name="schema">JPA_PART_ORAPOS</property>

                    </extension>

                 

                And all my jpa`s with this kind of declaration:

                 

                @Entity

                @Table(name="CATE_MVTO_PERSONA", schema="JPA_PART_ORAPOS")

                 

                And I have same result, don`t work. I have also changed in one JPA the declaration of a primary key from this: @Id to @EmbeddedId (I don´t know why with @Id it doesn`t work, I am with EclipseLink + Derby embedded).

                 

                When I go to select some data in the table in the embedded database, I get a Transaction Exception, informing that the view doesn`t exist:

                 

                javax.ejb.EJBTransactionRolledbackException

                 

                Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException

                Internal Exception: java.sql.SQLSyntaxErrorException: La tabla/vista 'JPA_PART_ORAPOS.CATE_MVTO_PERSONA' no existe.

                 

                This is my test-persistence.xml:

                 

                <?xml version="1.0" encoding="UTF-8"?>
                <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="         http://java.sun.com/xml/ns/persistence         http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
                    <persistence-unit name="ssogneis_sec_gneisbase_pu">
                        <jta-data-source>jdbc/arquillian</jta-data-source>
                        <class>com.gneis.obsidiana.gestion.jpa.BvUserProfile</class>
                        <class>com.gneis.obsidiana.gestion.jpa.UserInternet</class>
                        <properties>
                            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
                            <property name="eclipselink.logging.level.sql" value="FINE"/>
                            <property name="eclipselink.logging.parameters" value="true"/>
                        </properties>
                    </persistence-unit>
                    <persistence-unit name="ebkextracto_categorias_pu" transaction-type="JTA">
                        <jta-data-source>jdbc/arquillian</jta-data-source>
                        <class>com.gneis.ebkextracto.jpa.CateClaveConceptoJPA</class>
                        <class>com.gneis.ebkextracto.jpa.CateConceptoPersJPA</class>
                        <class>com.gneis.ebkextracto.jpa.CateConceptoPersJPAPK</class>
                        <class>com.gneis.ebkextracto.jpa.CateConPersonalizadoJPA</class>
                        <class>com.gneis.ebkextracto.jpa.CateConPersonalizadoJPAPK</class>
                        <class>com.gneis.ebkextracto.jpa.CateDesPersonaJPA</class>
                        <class>com.gneis.ebkextracto.jpa.CateDesPersonaJPAPK</class>
                        <class>com.gneis.ebkextracto.jpa.CateMvtoPersonaJPA</class>
                        <class>com.gneis.ebkextracto.jpa.CateMvtoPersonaJPAPK</class>
                  <properties>
                            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
                            <property name="eclipselink.logging.level.sql" value="FINE"/>
                            <property name="eclipselink.logging.parameters" value="true"/>
                        </properties>
                    </persistence-unit>
                </persistence>
                
                
                • 5. Re: Re: Re: Cannot populate table with Arquillian Persistence yml when jpa has table and Schema
                  casta_oh

                  Finally, I solved it as I explain here:

                   

                  1. I removed the schema name of each jpa class.

                  2. I add the next property to my persistence.xml file (production code):

                   

                  <properties>
                    <property name="openjpa.jdbc.Schema" value="JPA_PART_ORAPOS" />
                  
                  

                   

                  3. My test-persistence.xml doesn`t have any more the neccesity to create each table with its schema name before the name of the table.

                   

                  In this way, I managed it.

                   

                  I have found a problem that could be managed as an issue in Arquillian. When i use an extension, that sets up automatically some kind of annotation, it this pre-configuration fails, then the test seems to be as ok, but if I put a breakpoint inside my test, the debugger never arrives to the code, but the test results as "OK or PASSED".

                   

                  I have seen this behaviour with arquillian persistence, arquillian rest extension and using @ArquillianResource inside a normal test (not @RunAsClient).

                   

                  Regards-