Çağatay Kalan (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMWQ5ZmNmZmFi...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15457?atlOrigin=eyJpIjoiMWQ5Zm...
) HHH-15457 (
https://hibernate.atlassian.net/browse/HHH-15457?atlOrigin=eyJpIjoiMWQ5Zm...
) Could not resolve attribute "xx" of generic mapped superclass in criteria
queries (
https://hibernate.atlassian.net/browse/HHH-15457?atlOrigin=eyJpIjoiMWQ5Zm...
)
Issue Type: Bug Affects Versions: 6.1.1 Assignee: Unassigned Components: hibernate-core,
metamodel Created: 20/Aug/2022 22:24 PM Environment: Mac OS, JDK 17, Hibernate Core 6.1.1
Final Priority: Major Reporter: Çağatay Kalan (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
I have the following generic entity setup.
@Entity
open class User : DefaultJpaUser<TestUser, TestUserRole>() {
@NotBlank
override fun getUsername(): String? {
return super.getUsername()
}
}
@Entity
@Getter
@Setter
open class TestUserRole : DefaultJpaUserRole<TestUser, TestUserRole>() {
var modified: Instant? = null}
public abstract class DefaultJpaUser<
U extends DefaultJpaUser<U, UR>,
UR extends DefaultJpaUserRole<U, UR>>
extends JpaUser<Long, Long, DefaultJpaRole, UR, U> {
}
public abstract class DefaultJpaUserRole<
U extends DefaultJpaUser<U, UR>,
UR extends DefaultJpaUserRole<U, UR>>
extends JpaUserRole<Long, Long, DefaultJpaRole, U, UR> {
}
@Getter
@Setter
@NoArgsConstructorpublic
class JpaUserRole<
UID,
RID,
R extends JpaRole<RID>,
U extends JpaUser<UID, RID, R, UR, U>,
UR extends JpaUserRole<UID, RID, R, U, UR>> {
private UserRoleId<UID, RID> id = new UserRoleId<>();
@NotNull @ManyToOne @MapsId("userId")
private U user;
@NotNull @ManyToOne @MapsId("roleId")
private R role;
public JpaUserRole(UserRoleId<UID, RID> id) {
this.id = id;
}
@Embeddable
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class UserRoleId<UID, RID> implements Serializable {
@Serial private static final long serialVersionUID = 4710225845169939700L;
private UID userId;
private RID roleId;
}
}
public class JpaUser<UID,
RID,
R extends JpaRole<RID>,
UR extends JpaUserRole<UID, RID, R, U, UR>,
U extends JpaUser<UID, RID, R, UR, U>>
implements User<UID> {
UID id;
String username;
String password;
String email;
Boolean emailConfirmed;
Set<UR> roles = new HashSet<>();
public Set<UR> getRoles() {
return roles;
}
}
And I am trying to execute this criteria query:
var cb = entityManager.getCriteriaBuilder();
var q = cb.createQuery(Tuple.class);
var root = q.from(userRoleClass);
var userJoin = root.join("user");
q.where(cb.equal(userJoin.get("id"), user.getId()));
q.select(root.get("id"));
return entityManager.createQuery(q).getResultList()
.stream().map(row -> row.get(0,
Long.class).toString()).collect(Collectors.toList());
I get “could not resolve attribute id on JpaUserRole” error. Same issue occurs if I join
with “role” and query a role field.
I am not sure but this may be due to Hibernate resolving members from the declaring type
(JpaUserRole) instead of the persistent type (TestUserRole)
I traced the issue until “ org.hibernate.metamodel.internal. normalMemberResolver where
the member is resolved from the declaring type but could not go further. Maybe there is no
solution due to type erasure. I just wanted to learn if what I am trying to do is
possible.
Sorry that I have both Kotlin and Java code in the same issue 🙂
(
https://hibernate.atlassian.net/browse/HHH-15457#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15457#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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100205- sha1:5460ff5 )