[JIRA] (HHH-13990) org.hibernate.QueryException occurs When Join Fetch is used on toOne relationship along with memberOf filter on Element collection
by Chandrasekar Rajasekar (JIRA)
Chandrasekar Rajasekar ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea9ddf... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiM2UwOGFkODJi... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13990?atlOrigin=eyJpIjoiM2UwOG... ) HHH-13990 ( https://hibernate.atlassian.net/browse/HHH-13990?atlOrigin=eyJpIjoiM2UwOG... ) org.hibernate.QueryException occurs When Join Fetch is used on toOne relationship along with memberOf filter on Element collection ( https://hibernate.atlassian.net/browse/HHH-13990?atlOrigin=eyJpIjoiM2UwOG... )
Issue Type: Bug Affects Versions: 5.4.14 Assignee: Unassigned Components: hibernate-core Created: 29/Apr/2020 13:56 PM Priority: Major Reporter: Chandrasekar Rajasekar ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea9ddf... )
Query exception error occurs when element collection is included in where clause along with join fetch.
```java.lang.IllegalArgumentException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=example.Book.publisher,tableName=Publisher,tableAlias=publisher3_,origin=author author0_,columns={book2_.publisher_id ,className=example.Publisher}}] [SELECT example_Book FROM example.Author example_Author__fetch JOIN example_Author__fetch.books example_Book LEFT JOIN FETCH example_Book.publisher WHERE :awards_3b62d810_0 MEMBER OF example_Book.awards AND example_Author__fetch=:example_Author__fetch ] ```
`SELECT example_Book FROM example.Author example_Author_ fetch JOIN example_Author fetch.books example_Book LEFT JOIN FETCH example_Book.publisher WHERE :awards_3b62d810_0 MEMBER OF example_Book.awards AND example_Author fetch=:example_Author _fetch`
Book and author has many-many relationship and book and publisher has many-one relationship. Awards is a Element collection of type List<string>.
Some of working queries:
`SELECT example_Book FROM example.Book AS example_Book LEFT JOIN FETCH example_Book.publisher WHERE :awards_3e8093d5_0 MEMBER OF example_Book.awards `
`SELECT example_Book FROM example.Author example_Author_ fetch JOIN example_Author fetch.books example_Book LEFT JOIN FETCH example_Book.publisher WHERE example_Book.publishDate > :publishDate_fd2879ac_0 AND example_Author fetch=:example_Author _fetch`
( https://hibernate.atlassian.net/browse/HHH-13990#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13990#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:e06514a )
4 years, 8 months
[JIRA] (HHH-13989) Hibernate cannot correctly recognize the property named "count" in HQL
by King Netfix (JIRA)
King Netfix ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYWJmMTRhMGY4... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13989?atlOrigin=eyJpIjoiYWJmMT... ) HHH-13989 ( https://hibernate.atlassian.net/browse/HHH-13989?atlOrigin=eyJpIjoiYWJmMT... ) Hibernate cannot correctly recognize the property named "count" in HQL ( https://hibernate.atlassian.net/browse/HHH-13989?atlOrigin=eyJpIjoiYWJmMT... )
Change By: King Netfix ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
I have a Java entity managed by Hibernate as follows:
{ {
code:java} @Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
@Column(name = "`count`")
protected Integer count;
// omit getters / setters for brevity
} {code }
I want to execute a HQL statement as follows:
{ { code:sql}-- HQL:
update Product set count = 1 where id = 1
// -- executed by the following core code:
// -- org.hibernate.Session session = getSession();
// -- session.createQuery("HQL").executeUpdate();
{code } }
However it threw the following exception:
{{
{quote} java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.FromReferenceNode
at org.hibernate.hql.internal.ast.HqlSqlWalker.generateSyntheticDotNodeForNonQualifiedPropertyRef(HqlSqlWalker.java:745)
at org.hibernate.hql.internal.ast.HqlSqlWalker.lookupNonQualifiedProperty(HqlSqlWalker.java:738)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1176)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.assignment(HqlSqlBaseWalker.java:1061)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.setClause(HqlSqlBaseWalker.java:777)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:393)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:272)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:155)
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:604)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:716)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:113)
at me.codeplayer.test.dao.TransactionTest.test(TransactionTest.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
{quote } }
I could NOT understand the exception. I also want to work hard to find the error, , but to no avai.
Finally I renamed the "count" property to "counter". It miraculously worked fine.
Therefore, I suspect that Hibernate can NOT properly handle HQL containing reserved keywords such as "count".
If I remember correctly, I have used this in previous versions, but it has no problem.
( https://hibernate.atlassian.net/browse/HHH-13989#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13989#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:e06514a )
4 years, 8 months
[JIRA] (HHH-13989) Hibernate cannot correctly recognize the property named "count" in HQL
by King Netfix (JIRA)
King Netfix ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZTUzNTY0YzA3... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13989?atlOrigin=eyJpIjoiZTUzNT... ) HHH-13989 ( https://hibernate.atlassian.net/browse/HHH-13989?atlOrigin=eyJpIjoiZTUzNT... ) Hibernate cannot correctly recognize the property named "count" in HQL ( https://hibernate.atlassian.net/browse/HHH-13989?atlOrigin=eyJpIjoiZTUzNT... )
Issue Type: Bug Affects Versions: 5.4.14 Assignee: Unassigned Components: hibernate-core Created: 29/Apr/2020 12:28 PM Environment: Hibernate 5.4.14.Final, Oracle JDK 1.8.0_131, Windows 7 Ultimate 64 bit, MySQL 5.7.16-log Labels: HQL Priority: Major Reporter: King Netfix ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) Original Estimate: 1h Remaining Estimate: 1h
I have a Java entity managed by Hibernate as follows:
{{
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
@Column(name = "`count`")
protected Integer count;
// omit getters / setters for brevity
}}
I want to execute a HQL statement as follows:
{{
update Product set count = 1 where id = 1
// executed by the following core code:
// org.hibernate.Session session = getSession();
// session.createQuery("HQL").executeUpdate();
}}
However it threw the following exception:
{{
java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.FromReferenceNode
at org.hibernate.hql.internal.ast.HqlSqlWalker.generateSyntheticDotNodeForNonQualifiedPropertyRef(HqlSqlWalker.java:745)
at org.hibernate.hql.internal.ast.HqlSqlWalker.lookupNonQualifiedProperty(HqlSqlWalker.java:738)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1176)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.assignment(HqlSqlBaseWalker.java:1061)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.setClause(HqlSqlBaseWalker.java:777)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:393)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:272)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:155)
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:604)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:716)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:113)
at me.codeplayer.test.dao.TransactionTest.test(TransactionTest.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
}}
I could NOT understand the exception. I also want to work hard to find the error, , but to no avai.
Finally I renamed the "count" property to "counter". It miraculously worked fine.
Therefore, I suspect that Hibernate can NOT properly handle HQL containing reserved keywords such as "count".
If I remember correctly, I have used this in previous versions, but it has no problem.
( https://hibernate.atlassian.net/browse/HHH-13989#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13989#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:e06514a )
4 years, 8 months