[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5077) @OrderBy in combination with NamedQuery throws an error

Gail Badner (JIRA) noreply at atlassian.com
Mon Jan 10 22:44:05 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5077?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39548#action_39548 ] 

Gail Badner commented on HHH-5077:
----------------------------------

Is this still an issue using 3.6.0?

> @OrderBy in combination with NamedQuery throws an error
> -------------------------------------------------------
>
>                 Key: HHH-5077
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5077
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.5.0-Final
>         Environment: 0 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.0-Final
> 31 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.0-Final
> 47 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
> 47 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
> 63 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
> 360 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
> 375 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.5.0-Final
> Oracle 10g
>            Reporter: Thomas Götzinger
>         Attachments: orderby_bug.zip
>
>
> I have a OneToMany Relationship between ??ClientEntity?? and ??ChildEntity??. Both inherit from ??SuperEntity??.
> {code:title=SuperEntity.java|borderStyle=solid}
> @Entity
> @Inheritance(strategy = InheritanceType.JOINED)
> public class SuperEntity
> {
>   @Id
>   protected int id;
>   protected int position = 0;
> {code}
> Here is the Relationship-Definition of ClientEntity
> {code:title=ClientEntity.java|borderStyle=solid}
> public class ClientEntity
>     extends SuperEntity
> {
>   
>   public ClientEntity(int id)
>   {
>     this.id = id;
>   }
>   @OneToMany(fetch = FetchType.EAGER)
>   @JoinColumn(name = "parent_id")
>   @OrderBy("position")
>   List<ChildEntity> childs = new ArrayList<ChildEntity>();
> {code}
> The ??position??-Attribute (as well as the column) is located in the ??SuperEntity?? (Parent of ChildEntity), and should be used to order the entries of the list.
> {code:title=OrderByWithInheritanceTEst.java|borderStyle=solid}
> ClientEntity find = entityManager.find(ClientEntity.class, 1);
> {code}
> If I load the Entity with the find-Method or a NamedQuery the Exception beneath occurs:
> Hibernate fills in the tablename of the SuperEntity after the alias of the tablename of the ChildEntity and in front of the columnname.
> Hibernate indicates the wrong mapping at startup time of the SessionFactory. It prints out the following log:
> {code}
> orderByFragment(order-by)
>   > sortSpecification({sort specification})
>    > sortKeySpecification(sort key)
>     > sortKey($PlaceHolder$.SuperEntity.position)
> {code}
> *$PlaceHolder$.SuperEntity.position*
> The SQL-Output of Hibernate-Log (see the last part of the statement) shows that the wrong pattern above is used to address the position-column.
> {code}
> Hibernate: select cliententi0_.id as id0_1_, cliententi0_1_.position as position0_1_, childs1_.parent_id as parent2_0_3_, childs1_.id as id3_, childs1_.id as id0_0_, childs1_1_.position as position0_0_ from ClientEntity cliententi0_ inner join SuperEntity cliententi0_1_ on cliententi0_.id=cliententi0_1_.id left outer join ChildEntity childs1_ on cliententi0_.id=childs1_.parent_id left outer join SuperEntity childs1_1_ on childs1_.id=childs1_1_.id where cliententi0_.id=? order by childs1_.SuperEntity.position asc
> {code}
> *childs1_.SuperEntity.position asc*
> Beside the Wrong *SuperEntity*-Part the ??PlaceHolder?? has been replaced by the alias of the ChildEntity -table, whereas the alias of the SuperEntity-table would be the correct replacement.
> {quote}
> javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not load an entity: [net.goetzingert.orderbytest.ClientEntity#1]
> 	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1179)
> 	at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:575)
> 	at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:529)
> 	at net.goetzingert.orderbytest.OrderByWithInheritanceTEst.testFind(OrderByWithInheritanceTEst.java:44)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> 	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> 	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
> 	at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
> 	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> 	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: org.hibernate.exception.SQLGrammarException: could not load an entity: [net.goetzingert.orderbytest.ClientEntity#1]
> 	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
> 	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
> 	at org.hibernate.loader.Loader.loadEntity(Loader.java:1937)
> 	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
> 	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
> 	at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3270)
> 	at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
> 	at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
> 	at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
> 	at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
> 	at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
> 	at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1080)
> 	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:997)
> 	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:990)
> 	at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:554)
> 	... 26 more
> Caused by: java.sql.SQLException: ORA-00904: "CHILDS1_"."SUPERENTITY"."POSITION": invalid identifier
> 	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
> 	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
> 	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
> 	at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
> 	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)
> 	at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:796)
> 	at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1031)
> 	at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:836)
> 	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1124)
> 	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
> 	at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
> 	at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
> 	at org.hibernate.loader.Loader.getResultSet(Loader.java:1849)
> 	at org.hibernate.loader.Loader.doQuery(Loader.java:718)
> 	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
> 	at org.hibernate.loader.Loader.loadEntity(Loader.java:1933)
> 	... 38 more
> {quote}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list