[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-7231) @OrderBy fails if order by property is in inherited superclass
Roberto Ruiz (JIRA)
noreply at atlassian.com
Sun Apr 22 19:53:48 EDT 2012
[ https://hibernate.onjira.com/browse/HHH-7231?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Roberto Ruiz updated HHH-7231:
------------------------------
Attachment: hibernate-inherited-orderby-test.zip
Test case. Requires Maven 3 and Java 6
Execute "mvn test"
> @OrderBy fails if order by property is in inherited superclass
> --------------------------------------------------------------
>
> Key: HHH-7231
> URL: https://hibernate.onjira.com/browse/HHH-7231
> Project: Hibernate ORM
> Issue Type: Bug
> Components: entity-manager
> Affects Versions: 4.1.1
> Environment: Java 1.6
> Windows XP SP3
> Eclipse 3.6
> Spring 3.1.1
> MySQL (Same error in oracle and HSQLDB)
> Reporter: Roberto Ruiz
> Attachments: hibernate-inherited-orderby-test.zip
>
>
> I try to order a Set or List mapped by @ManyToOne using a property that is in the inherited superclass of the child side.
> When I try to recover the Set, the query fails because generated SQL is wrong
> Next I write a simplified example (getters an setter ommited):
> @Entity
> @Table(name="PLACE")
> @Inheritance(strategy=InheritanceType.JOINED)
> public abstract class Place {
> @Id
> @Column(name="PLACE_ID")
> private Long id;
>
> @Column(name="PLACE_NAME")
> private String name;
> }
> @Entity
> @Table(name="LOCALITY")
> @PrimaryKeyJoinColumn(name="PLACE_ID", referencedColumnName="PLACE_ID")
> public class Locality extends Place {
> @Column(name="LOCALITY_MAJOR")
> private String major;
> @OneToMany(mappedBy="locality")
> @OrderBy("historyCount")
> private Set<LocalityHistorical> history;
> }
> @Entity
> @Table(name="PLACE_HIST")
> @Inheritance(strategy=InheritanceType.JOINED)
> public abstract class PlaceHistorical {
> @Id
> @Column(name="HIST_PLACE_ID")
> private Long id;
>
> @Column(name="HIST_PLACE_NAME")
> private String name;
>
> @Column(name="HIST_COUNT")
> private Long historyCount;
> }
> @Entity
> @Table(name="LOCALITY_HIST")
> @PrimaryKeyJoinColumn(name="HIST_PLACE_ID", referencedColumnName="HIST_PLACE_ID")
> public class LocalityHistorical extends PlaceHistorical {
> @ManyToOne(optional=false)
> @JoinColumn(name="PLACE_ID")
> private Locality locality;
>
> @Column(name="LOCALITY_MAJOR")
> private String major;
> }
> As you may see in the example, the entity "Locality" has a Set called histiry of "LocalityHistorical". The set is ordered by historyCount which is a field of the superentity "PlaceHistorical".
> The generated SQL is:
> select
> history0_.PLACE_ID as PLACE3_0_1_,
> history0_.HIST_PLACE_ID as HIST2_1_,
> history0_.HIST_PLACE_ID as HIST1_2_0_,
> history0_1_.HIST_COUNT as HIST2_2_0_,
> history0_1_.HIST_PLACE_NAME as HIST3_2_0_,
> history0_.PLACE_ID as PLACE3_3_0_,
> history0_.LOCALITY_MAJOR as LOCALITY1_3_0_
> from
> LOCALITY_HIST history0_
> inner join
> PLACE_HIST history0_1_
> on history0_.HIST_PLACE_ID=history0_1_.HIST_PLACE_ID
> where
> history0_.PLACE_ID=?
> order by
> history0_.PLACE_HIST.HIST_COUNT asc
> The error is in the order by clause which should be "history0_1_.HIST_COUNT" instead of "history0_.PLACE_HIST.HIST_COUNT"
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list