Query Problems with ORM 5.6.6. and 5.6.7

Several queries not working anymore since I’ve upgraded from 5.6.5.
A simple restriction on a ManytoOne attribute leads to a Ora-904 Error. The same query together with 5.6.5 or lower versions works.

I don’t know how you expect anyone to help you with this little information you gave. What queries? How does the model look like? What is the stack trace?

Did you even care to look through other posts to see how other people report issues or ask questions?

Dear commuity, as promised before, here’s the testcase below. May be I’ve found a bug. Let’s see.

The query works with Hibernate ORM 5.6.5 or older. From 5.6.6 up to 5.6.9 the query fails with the stacktrace below.

The key ist the Annotation “@NotFound(action = NotFoundAction.IGNORE)”. If it is omitted on the DetailB-Attribute in class MasterA then the query works in 5.6.9 too.

Oracle

CREATE TABLE master_a (
id_a INTEGER,
detail_b_id INTEGER
);

CREATE TABLE detail_b (
id_b INTEGER,
some_status INTEGER
);

create table variant_c_of_b (
id_b INTEGER
);

create table variant_d_of_b (
id_b INTEGER
);

(no values needed)

Java

  • Model:
@Entity
@DynamicUpdate
@Table(name = "ecm_vbm.master_a")
public class MasterA {
  @Id
  @Column(name = "id_a")
  private Integer id;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "detail_b_id")
  @NotFound(action = NotFoundAction.IGNORE)
  private DetailB detailB;

  // Getters Setters omitted
}

@Entity
@DynamicUpdate
@Table(name = "ecm_vbm.detail_b")
@Inheritance(strategy = InheritanceType.JOINED)
public class DetailB {
  @Id
  @Column(name = "id_b")
  private Integer id;

  @Column(name = "some_status")
  private Integer someStatus;

  // Getters Setters omitted
}

@Entity
@Table(name = "ecm_vbm.variant_c_of_b")
@PrimaryKeyJoinColumn(name = "id_b")
public class VariantCofB extends DetailB {
}

@Entity
@Table(name = "ecm_vbm.variant_d_of_b")
@PrimaryKeyJoinColumn(name = "id_b")
public class VariantDofB extends DetailB {
}
  • Query:

CriteriaBuilder cb0 = session.getCriteriaBuilder();
CriteriaQuery q0 = cb0.createQuery(MasterA.class);
Root root0 = q0.from(MasterA.class);
q0.select(root0);
q0.where(cb0.equal(root0.get(“detailB”).get(“someStatus”), 5));
List list0 = session.createQuery(q0).getResultList();
System.out.println("list0: " + list0.size());

– generated SQL:

Hibernate: select mastera0_.id_a as id_a1_362_0_, detailb1_.id_b as id_b1_361_1_, mastera0_.detail_b_id as detail_b_id2_362_0_, detailb1_.some_status as some_status2_361_1_, case when detailb1_1_.id_b is not null then 1 when detailb1_2_.id_b is not null then 2 when detailb1_.id_b is not null then 0 end as clazz_1_ from ecm_vbm.master_a mastera0_ cross join ecm_vbm.detail_b detailb1_ where mastera0_.detail_b_id=detailb1_.id_b and detailb1_.some_status=5

– stacktrace:

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1626)
at org.hibernate.query.Query.getResultList(Query.java:165)
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:76)
at com.thyssenkrupp.tks.ecm.ecmmailing.util.ContainmentUtil.doStage4(ContainmentUtil.java:409)
at com.thyssenkrupp.tks.ecm.ecmmailing.util.ContainmentUtil.doJob(ContainmentUtil.java:70)
at com.thyssenkrupp.tks.ecm.ecmmailing.ejb.EmailJobBean.containment(EmailJobBean.java:991)
at com.thyssenkrupp.tks.ecm.ecmmailing.ejb.EmailJobBean_n9zo82_RemoteEmailingJobImpl.__WL_invoke(Unknown Source)
at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:35)
at com.thyssenkrupp.tks.ecm.ecmmailing.ejb.EmailJobBean_n9zo82_RemoteEmailingJobImpl.containment(Unknown Source)
at com.thyssenkrupp.tks.ecm.ecmmailing.ejb.EmailJobBean_n9zo82_RemoteEmailingJobImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:645)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:246)
at weblogic.rmi.internal.BasicServerRef$2.run(BasicServerRef.java:534)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:368)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:163)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:531)
at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:138)
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:348)
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)
at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)
at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:37)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2322)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2075)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2037)
at org.hibernate.loader.Loader.doQuery(Loader.java:956)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:357)
at org.hibernate.loader.Loader.doList(Loader.java:2868)
at org.hibernate.loader.Loader.doList(Loader.java:2850)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2682)
at org.hibernate.loader.Loader.list(Loader.java:2677)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:540)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1459)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1649)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617)
… 23 more
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "DETAILB1_2
".“ID_B”: ungültige ID

Thanks for the details. If you could create a JIRA issue for this and ideally also a reproducer in the form of our standard test case example, that would be of great help to us!

HHH-15299

Unfortunately I was unable to set up the standard test case but I think the added custom test case is short and simple enough.

Thanks. What do you mean by “custom test case”? You mean the code snippets you provided? I just hope we can reproduce your issue when copy-pasting the snippets to a test case. See, if we can’t this will probably delayed even further, hence it would be best if you could provide us with such a test by yourself.

I’ve been working (intensivley) with Hibernate for 15 years and it’s first issue/obstacle I’ve to deal with. Unfortunately I’m not familar with CI/CD and JUnit so I don’t know how to integrate a SQL create table script into a test case. The added snippets will work I guarantee.
Best regards,
Steffen

I suggest connections/relations to HHH-15304