Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2533

Table name defined in XML mapping file is not used when executing a named query.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.2.2, 2.3.0, 2.4.0
    • Fix Version/s: 2.2.3, 2.4.0
    • Component/s: query
    • Labels:
      None

      Description

      Take this simple entity:

      @Entity
      @javax.persistence.NamedQuery(name = "TableNameInXmlEntity.findAll", query = "SELECT t FROM TableNameInXmlEntity t")
      public class TableNameInXmlEntity implements Serializable {
      @Id
      private int myid;
      .......

      Take this simple XML mapping entry:

      <entity-mappings..........
      <entity class="org.apache.openjpa.persistence.xml.TableNameInXmlEntity">
      <table name="TableNameInXml"/>
      </entity>
      </entity-mappings>

      With this code, take the following test to execute the named query:

      Query q = em.createNamedQuery("TableNameInXmlEntity.findAll");
      q.getResultList();

      The following SQL will be generated:

      SELECT t0.myid FROM TableNameInXmlEntity t0

      Notice that 'TableNameInXmlEntity' is used, rather than 'TableNameInXml' (i.e. the name defined in the XML mapping file).

      Rather than executing a named query, if we execute a query like the following:

      Query q = em.createQuery("SELECT t FROM TableNameInXmlEntity t");
      q.getResultList();

      The following (correct) SQL will be executed:

      SELECT t0.myid FROM TableNameInXml t0

      Finally, if we executed the above query, and THEN execute the named query, all will work as expected.

      I have a test I'll upload shortly which recreates the issue.

      Thanks,

      Heath

        Activity

        Hide
        jpaheath Heath Thomann added a comment -

        Providing a test to recreate the issue.

        Thanks,

        Heath

        Show
        jpaheath Heath Thomann added a comment - Providing a test to recreate the issue. Thanks, Heath
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1632647 from Rick Curtis in branch 'openjpa/trunk'
        [ https://svn.apache.org/r1632647 ]

        OPENJPA-2533: Reorder MetaDataRepository call to fix a bug in orm resloution.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1632647 from Rick Curtis in branch 'openjpa/trunk' [ https://svn.apache.org/r1632647 ] OPENJPA-2533 : Reorder MetaDataRepository call to fix a bug in orm resloution.
        Hide
        curtisr7 Rick Curtis added a comment -

        Committed revision 1632647 to trunk.

        Show
        curtisr7 Rick Curtis added a comment - Committed revision 1632647 to trunk.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1644778 from Heath Thomann in branch 'openjpa/branches/2.2.x'
        [ https://svn.apache.org/r1644778 ]

        OPENJPA-2533: Table name defined in XML mapping file is not used when executing a named query. Back ported to 2.2.x Rick Curtis' trunk commit.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1644778 from Heath Thomann in branch 'openjpa/branches/2.2.x' [ https://svn.apache.org/r1644778 ] OPENJPA-2533 : Table name defined in XML mapping file is not used when executing a named query. Back ported to 2.2.x Rick Curtis' trunk commit.

          People

          • Assignee:
            curtisr7 Rick Curtis
            Reporter:
            jpaheath Heath Thomann
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development