Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-15899

[GSS](7.2.z) HHH-13114 Query "select count(h) from Human h" fails if a subclass has a non-Id property named "id"

    XMLWordPrintable

    Details

      Description

      *no* further _formatting_ is done here
      

      Given the following classes:

       @Entity(name = "Genius")
      	public static class Genius extends Human {
      		private Long id;
      
      		public Genius() {
      		}
      
      		public Genius(Long id) {
      			this.id = id;
      		}
      
      		public Long getId() {
      			return id;
      		}
      
      		public void setId(Long id) {
      			this.id = id;
      		}
      	}
      
      	@Entity(name = "Human")
      	@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
      	public static class Human {
      		private Long realId;
      
      		@Id
      		@GeneratedValue(strategy = GenerationType.AUTO)
      		@Column(name = "realId")
      		public Long getRealId() {
      			return realId;
      		}
      
      		public void setRealId(Long realId) {
      			this.realId = realId;
      		}
      	}
      

      Executing the query: select count( h ) from Human h results in the following SQL:

      select
              count(idproperty0_.id) as col_0_0_ 
          from
              Human idproperty0_
      

      Note that:

      • idproperty0_.id is not the primary key column;
      • Human does not have a property named id;
      • count should be operating on the primary key, idproperty0_.realId.
        The same select expression is generated using @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS).
        When @Inheritance(strategy = InheritanceType.JOINED) is used, the generated SQL is:
       select
              count(idproperty0_1_.id) as col_0_0_ 
          from
              Human idproperty0_
      

      In addition to using the wrong column, there is no table with alias idproperty0_1_.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              gbadner Gail Badner
              Reporter:
              raggz Tom Ross
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: