[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-5225) Cannot parse order-by fragment if it contains a registered function without parentheses
Gail Badner (JIRA)
noreply at atlassian.com
Thu Aug 19 19:59:42 EDT 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5225?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gail Badner resolved HHH-5225.
------------------------------
Resolution: Fixed
Fixed in trunk and Branch_3_5.
This is kind of complicated, but here is how it works...
Hibernate will interpret order-by="current_date" as follows:
1) if current_date is NOT registered as a function with the dialect, then Hibernate will assume current_date refers to a column name;
2) if current_date is registered as a function that must be followed by parentheses (SQLFunction.hasParenthesesIfNoArguments() == true), then Hibernate will assume current_date refers to a column (since the order-by fragment does not have "()")
3) if current_date is registered as a function without parentheses (i.e., SQLFunction.hasParenthesesIfNoArguments() == false), then Hibernate will assume current_date refers to the no-arg function, not a column.
If the fragment is order-by="`current_date`" (i.e., back-quotes surround the string), then Hibernate will assume that it refers to a column, even if a function with the same name is registered. You can use back-quotes to override 3).
> Cannot parse order-by fragment if it contains a registered function without parentheses
> ---------------------------------------------------------------------------------------
>
> Key: HHH-5225
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5225
> Project: Hibernate Core
> Issue Type: Bug
> Affects Versions: 3.5.1, 3.5.2, 3.6.0.Beta2
> Environment: Hibernate 3.5.1-Final
> MySQL 5.0
> Spring 2.5
> Reporter: Vladimir Kobetic
> Assignee: Gail Badner
> Priority: Critical
> Fix For: 3.6.0.Beta4, 3.5.6
>
> Attachments: TestOrderBy.tgz
>
>
> When upgrading from Hibernate 3.2.5.ga to the newest Hibernate 3.5.1-Final with the newest build-with dependent libraries an error occurs during initial phase of launching application.
> I tried to build and run with all libraries from lib directory from Hibernate zip download.
> The order-by clause is configured in hbm.xml:
> <hibernate-mapping>
> <class name="com.test.Object" table="err">
> <id name="id" type="java.lang.Long">
> <generator class="native" />
> </id>
> <set name="history" table="history" lazy="true" order-by="timestamp desc" cascade="all-delete-orphan">
> <key column="object_id" />
> <one-to-many class="com.test.Event" />
> </set>
> </class>
> </hibernate-mapping>
> The exception is:
> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext-dao-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to parse order-by fragment
> Caused by: org.hibernate.HibernateException: Unable to parse order-by fragment
> at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.render(OrderByFragmentTranslator.java:66)
> at org.hibernate.sql.Template.renderOrderByStringTemplate(Template.java:310)
> at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:557)
> at org.hibernate.persister.collection.OneToManyPersister.<init>(OneToManyPersister.java:84)
> at org.hibernate.persister.PersisterFactory.createCollectionPersister(PersisterFactory.java:104)
> and more...
> Caused by: java.lang.NullPointerException
> at org.hibernate.sql.ordering.antlr.OrderByFragmentParser.resolveFunction(OrderByFragmentParser.java:115)
> at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.expression(GeneratedOrderByFragmentParser.java:619)
> at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.sortKey(GeneratedOrderByFragmentParser.java:337)
> at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.sortSpecification(GeneratedOrderByFragmentParser.java:248)
> at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.orderByFragment(GeneratedOrderByFragmentParser.java:192)
> at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.render(OrderByFragmentTranslator.java:60)
> ... 38 more
--
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