Since upgrading to Spring Boot 3.x and Hibernate 6, pretty much all of my JPQL fails to execute and I’ve had to revert to native SQL queries. I keep trying new version of spring/hibernate as they get released but as of Spring Boot 3.2.2 and Hibernate 6.4.1, this problem has persisted. I don’t know if it’s the way I’ve written my schema, or the way I’m writing my JPQL so I have to ask the community.
(I’ll try to make this make sense. I’m not good at documenting table relations.)
@Entity(name = "workgroup")
class Workgroup {
@Id
long id;
String name;
}
@Entity(name = "user")
class User {
@Id
long id;
String name;
@ManyToOne
Workgroup workgroup;
}
@Entity(name = "request")
class Request {
@Id
long id;
@ManyToOne
Workgroup workgroup;
@ManyToOne
User requester;
@ManyToOne
User assignedTo;
}
That’s the basic entity structure. Three tables, workgroup, user and request. My JPQL will be:
select r.id, w.name, req.name, asn.name
from request r
inner join user req on r.requester.id = req.id
inner join user asn on r.assignedTo.id = asn.id
I use Query q = entityManager.createQuery(jpql, Tuple.class)
and List<Tuple> rs = q.getResultList()
This results in an error of: Multiple from-elements expose unqualified attribute : workgroup
It’s coming from line 148 of SqmPathRegistryImpl.class. The first found
fromElement will be one of the paths, and it appears to clearly have the alias in it. When the second path is found, with a different alias, it just checks that found
is not null and throws the error. It almost seems like I can’t join to the same table twice in the same query. Something I did a lot of with Hibernate 5.
So my question is, am I not aliasing the tables properly? Or do I have something wrong with my entities or relations?