# Possible Regresssion in SemanticQueryBuilder 6.4.4 -\> 6.5.2

**URL:** <https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612>\
**Category:** Hibernate ORM\
**Created:** [May 27, 2024, 5:07pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612 "2024-05-27T17:07:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevinm416](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kevinm416/32/2892_2.png) [@kevinm416](https://discourse.hibernate.org/u/kevinm416)\
**Post date:** [May 27, 2024, 5:07pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/1 "2024-05-27T17:07:08Z")

</div>

I’m attempting to update a spring-boot app to 3.3.0, which involves hibernate being bumped from 6.4.4 to 6.5.2. After the bump, a number of queries are failing. In particular, I’ve been debugging this one:

```auto
public record Summary(
    long productionRunId, long productId, String productLengthName, long count, double volume) { }

```

```auto
  @Query(
      """
      SELECT new com.example.Summary(
        t.productionRun.id,
        t.product.id,
        t.productLengthName,
        COUNT(*),
        SUM(t.volume)
      )
      FROM Tag t
      GROUP BY t.productionRun.id, t.product.id, t.productLengthName
      """)
  List<Summary> getSummaries();

```

```auto
Caused by: org.hibernate.query.SemanticException: Missing constructor for type 'Summary'
    at app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitInstantiation(SemanticQueryBuilder.java:1506)
    at app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitInstantiation(SemanticQueryBuilder.java:275)
    at app//org.hibernate.grammars.hql.HqlParser$InstantiationContext.accept(HqlParser.java:4029)
    at app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSelectableNode(SemanticQueryBuilder.java:1453)
    at app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSelection(SemanticQueryBuilder.java:1407)

```

I set some breakpoints to see what was going wrong, and I see that the types that Hibernate is looking for in the constructor do not match the types in `Summary`:

 ![Screenshot 2024-05-27 at 12.01.14 PM](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/4/4d903242bdc6652d9ed79f7039081feb073a70b4.jpeg)

The issue is with the first element from `argumentTypes`, which is reported as `Void`. The query for that first argument is:

```auto
SELECT new com.example.Summary(
        t.productionRun.id,

```

It seems clear to me that parameter is `Long` and not `Void`, especially since this works in 6.4.4.

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [May 28, 2024, 6:53am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/2 "2024-05-28T06:53:52Z")

</div>

This sounds like a bug. Please try to create a [test case](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the error you’re encountering and open a new ticket in our [issue tracker](https://hibernate.atlassian.net/browse/HHH).

---

<div class="post-metadata">

**Author:** ![kevinm416](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kevinm416/32/2892_2.png) [@kevinm416](https://discourse.hibernate.org/u/kevinm416)\
**Post date:** [May 28, 2024, 2:27pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/3 "2024-05-28T14:27:34Z")

</div>

Hi Marco, thank you for the direction. I wrote the test case but unfortunately, I can not reproduce the issue. I’m not sure where to go from here.

To make it closer to my setup, I’d need to use a Repository to define the query instead of using EntityManager, but I don’t see an example of that, and the classes aren’t part of the test case project.

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [May 28, 2024, 3:24pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/4 "2024-05-28T15:24:18Z")

</div>

If you cannot reproduce the problem in the template, using plain Hibernate, it means that it might be caused by an external factor. Since it sounds like you’re using Spring Data, I would suggest asking those folks for help.

---

<div class="post-metadata">

**Author:** ![JGlink](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/jglink/32/3245_2.png) [@JGlink](https://discourse.hibernate.org/u/JGlink)\
**Post date:** [May 29, 2024, 9:36am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/6 "2024-05-29T09:36:14Z")

</div>

I came across the same error when upgrading to 6.5.2 (using Quarkus).  
It was a similar situation; the isConstructorCompatible method did not find the correct constructor.

In my case it was because of a generic field in an entity which was seen as “Serializeable” which strangely did not match the “String” type in the DTO constructor.

This has just recently changed with [[HHH-17729] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-17729)

---

<div class="post-metadata">

**Author:** ![JGlink](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/jglink/32/3245_2.png) [@JGlink](https://discourse.hibernate.org/u/JGlink)\
**Post date:** [May 29, 2024, 9:43am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/7 "2024-05-29T09:43:41Z")

</div>

If org.hibernate.query.sqm.tree.expression.Compatibility#areAssignmentCompatible line #62 would switch the parameters from

```auto
to.isAssignableFrom(from)

```

to

```auto
from.isAssignableFrom(to)

```

it would work in my example where a entity defines a field as generic type but the constructor defines the concrete type.

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [May 29, 2024, 2:36pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/8 "2024-05-29T14:36:51Z")

</div>

@JGlink can you reproduce the issue using Hibernate only? If so, it would be great it you could share a reproducer and open a Jira issue so someone will be able to look into it.

---

<div class="post-metadata">

**Author:** ![Spunc](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@Spunc](https://discourse.hibernate.org/u/Spunc)\
**Post date:** [May 31, 2024, 9:43am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/9 "2024-05-31T09:43:20Z")

</div>

I can confirm the problem.

I am also using Spring-Boot 3.3.0, but it is possible to override the Hibernate version by setting a property (for Maven builds this is `<hibernate.version>6.4.8.Final</hibernate.version>`.

By playing around with versions, I observed that the problem was introduced when upgrading from 6.4.8.Final to 6.5.0.Final (and above).

---

<div class="post-metadata">

**Author:** ![cigaly](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/cigaly/32/2390_2.png) [@cigaly](https://discourse.hibernate.org/u/cigaly)\
**Post date:** [June 1, 2024, 10:23am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/10 "2024-06-01T10:23:13Z")

</div>

@kevinm416 Can you, please, include your entities in post? Without those is almost imposible to duplicate your problem.

---

<div class="post-metadata">

**Author:** ![kevinm416](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kevinm416/32/2892_2.png) [@kevinm416](https://discourse.hibernate.org/u/kevinm416)\
**Post date:** [June 1, 2024, 3:20pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/11 "2024-06-01T15:20:02Z")

</div>

There’s really nothing surprising in the entities that can’t be inferred from the query I shared, but I understand you don’t want to make assumptions. I’d also prefer not to post the entities in their entirety, but here are all the entities with all the fields used by the query + tenantId.

```auto
@Entity
@Getter
@Accessors(chain = true)
@Setter
public class Tag {

  @Id @GeneratedValue private long id;

  @TenantId
  @Column(name = "tenant_id", nullable = false, updatable = false)
  private Long tenantId;

  @ManyToOne(fetch = FetchType.LAZY, optional = false)
  private Product product;

  @Column(name = "product_length_name", nullable = false)
  private String productLengthName;

  @ManyToOne(fetch = FetchType.LAZY, optional = false)
  private ProductionRun productionRun;
}

@Entity
@Getter
@Accessors(chain = true)
@Setter
public class ProductionRun {
  @Id @GeneratedValue private long id;

  @TenantId
  @Column(name = "tenant_id", nullable = false, updatable = false)
  private Long tenantId;
}

@Entity
@Getter
@Accessors(chain = true)
@Setter
public class Product {
  @Id @GeneratedValue private long id;

  @TenantId
  @Column(name = "tenant_id", nullable = false, updatable = false)
  private Long tenantId;
}

```

Lombok annotations are used to create getters + setters.

This is what I used to attempt to recreate the issue in the test case repository, hopefully you have better luck than I did!

---

<div class="post-metadata">

**Author:** ![cigaly](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/cigaly/32/2390_2.png) [@cigaly](https://discourse.hibernate.org/u/cigaly)\
**Post date:** [June 2, 2024, 6:12am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/12 "2024-06-02T06:12:52Z")

</div>

Thanks! I will try to reproduce your problem.

I think if “missing constructor” exception will not show if you change productionRunId in Summary from long to java.lang.Long (i.e. wrapper instead of primitive type) . However, this may not be fix for the issue. For some (unknown at the moment) reason this first argument is treated as null. See lines in org.hibernate.query.sqm.tree.expression.Compatibility.areAssignmentCompatible:

```auto
		if ( from == Void.class && !to.isPrimitive() ) {
			// treat Void as the bottom type, the class of null
			return true;
		}

```

So, if the only problem (bug) is why first parameter is treated as Void/null, this might be cure for your problem.

---

<div class="post-metadata">

**Author:** ![JGlink](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/jglink/32/3245_2.png) [@JGlink](https://discourse.hibernate.org/u/JGlink)\
**Post date:** [June 3, 2024, 4:52am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/13 "2024-06-03T04:52:03Z")

</div>

In my case, the entities looks like this and the issue occurs with the “id” field coming from the base class.

Base class:

```auto
@MappedSuperclass
public abstract class AbstractEntity<K extends Serializable> extends PanacheEntityBase {
   @Id
   protected K id;

   protected K getId() { return id; }

   protected void setId(K id) {
       this.id = id;
   }
}

```

And a sample of a concrete entity:

```auto
@Getter
@Setter
@Entity
public class MyConcreteEntity extends AbstractEntity<Long> {
   protected String someOtherField;
}

```

A DTO containing the Id field from the abstract class and the fields of the concrete class:

```auto
public class MyConcreteDto {
   protected Long id;

   protected String someOtherField;

   public MyConcreteDto(Long id, String someOtherField) {
      this.id = id;
      this.someOtherField = someOtherField;
   }
}

```

When executing a query with projection into the DTO, I need to cast the generic “id” field of the abstract entity to long; otherwise I get an error that no matching constructor was found.

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [June 3, 2024, 7:17am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/14 "2024-06-03T07:17:09Z")

</div>

Thanks @JGlink and @kevinm416 for sharing your entity and DTO mappings. I was able to reproduce the issue in a simple project using Hibernate only, and I have created a bug report [[HHH-18218] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-18218).

Feel free to watch the issue to receive any updates on a fix and vote for it to increase visibility.

---

<div class="post-metadata">

**Author:** ![JGlink](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/jglink/32/3245_2.png) [@JGlink](https://discourse.hibernate.org/u/JGlink)\
**Post date:** [June 3, 2024, 7:26am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/15 "2024-06-03T07:26:25Z")

</div>

Great to hear. Thanks.

---

<div class="post-metadata">

**Author:** ![kevinm416](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kevinm416/32/2892_2.png) [@kevinm416](https://discourse.hibernate.org/u/kevinm416)\
**Post date:** [June 3, 2024, 2:01pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/16 "2024-06-03T14:01:33Z")

</div>

@mbladel Did you try reproducing the issue without using abstract classes or generic keys? My issue has neither of those. All entity fields were concrete and matched the DTO fields.

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [June 3, 2024, 3:46pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/17 "2024-06-03T15:46:44Z")

</div>

@kevinm416 no, if you couldn’t reproduce the issue yourself it will be very hard for anyone else to try with only partial access to your mappings, but from what I can see the dynamic instantiation in your query should work. As I said, if you cannot reproduce with pure Hibernate maybe something else is breaking along the way.

---

<div class="post-metadata">

**Author:** ![kevinm416](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kevinm416/32/2892_2.png) [@kevinm416](https://discourse.hibernate.org/u/kevinm416)\
**Post date:** [June 22, 2024, 4:35pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/18 "2024-06-22T16:35:05Z")

</div>

I was able to reproduce a similar regression involving SemanticQueryBuilder in a different query that started failing in 6.4.8 including a test case: [[HHH-18291] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-18291).

@Spunc mentioned being able to change hibernate versions, but it took me a while to figure out how to do that. In the root gradle file, I used this line to override the hibernate version being used by spring-boot:

```auto
ext['hibernate.version'] = '6.4.8.Final'

```

That allowed me to figure out the exact hibernate version where the regression happened before attempting to write the test case, and also confirm it was specific to Hibernate.

---

<div class="post-metadata">

**Author:** ![cigaly](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/cigaly/32/2390_2.png) [@cigaly](https://discourse.hibernate.org/u/cigaly)\
**Post date:** [June 23, 2024, 7:07am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/19 "2024-06-23T07:07:05Z")

</div>

Thanks for test case

---

<div class="post-metadata">

**Author:** ![kevinm416](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kevinm416/32/2892_2.png) [@kevinm416](https://discourse.hibernate.org/u/kevinm416)\
**Post date:** [June 23, 2024, 2:21pm UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/20 "2024-06-23T14:21:11Z")

</div>

And now that I have the `ext` trick for forcing the Hibernate version, and got past that other regression in `6.4.8.Final`, here is a reproduction of the original issue: [[HHH-18292] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-18292). The regression happened between `6.4.9.Final` and `6.5.0.Final` and is present in the most recent `6.5.2.Final` release.

---

<div class="post-metadata">

**Author:** ![JGlink](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/jglink/32/3245_2.png) [@JGlink](https://discourse.hibernate.org/u/JGlink)\
**Post date:** [June 24, 2024, 11:03am UTC](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612/21 "2024-06-24T11:03:20Z")

</div>

Is there a timeframe for the 6.5.3 release?

[Next page](https://discourse.hibernate.org/t/possible-regresssion-in-semanticquerybuilder-6-4-4-6-5-2/9612.md?page=2)
