Fouad Almalki (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNGQ0ODBiZjU3...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16408?atlOrigin=eyJpIjoiNGQ0OD...
) HHH-16408 (
https://hibernate.atlassian.net/browse/HHH-16408?atlOrigin=eyJpIjoiNGQ0OD...
) query.setMaxResults(1) with EntityGraph and @ElementCollection gives wrong result in
Hibernate 6 (
https://hibernate.atlassian.net/browse/HHH-16408?atlOrigin=eyJpIjoiNGQ0OD...
)
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Components: hibernate-core
Created: 30/Mar/2023 20:21 PM Priority: Critical Reporter: Fouad Almalki (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Given:
@Table(name = "users" )
@Entity
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id" )
Integer id;
@NotNull
@Column(name = "username" )
String username;
@ElementCollection
@CollectionTable(name = "users_roles_mapping" , joinColumns = @JoinColumn(name
= "user_id" ))
@Column(name = "role_name" )
Set< String > roles;
// ...
}
CREATE TABLE users (
id INT NOT NULL IDENTITY ,
username VARCHAR (50) NOT NULL ,
CONSTRAINT pk_users PRIMARY KEY (id)
);
CREATE TABLE roles (
name VARCHAR (50) NOT NULL ,
CONSTRAINT pk_roles PRIMARY KEY ( name )
);
CREATE TABLE users_roles_mapping (
user_id INT NOT NULL ,
role_name VARCHAR (50) NOT NULL ,
CONSTRAINT pk_users_roles_mapping PRIMARY KEY (user_id, role_name),
CONSTRAINT fk_users_roles_mapping_user FOREIGN KEY (user_id) REFERENCES users (id),
CONSTRAINT fk_users_roles_mapping_role FOREIGN KEY (role_name) REFERENCES roles ( name
)
);
INSERT INTO users (username) VALUES ( 'user1' );
INSERT INTO roles ( name ) VALUES ( 'role1' ), ( 'role2' );
INSERT INTO users_roles_mapping (user_id, role_name) VALUES (1, 'role1' ), (1,
'role2' );
public Set< String > getUserRoles() {
EntityGraph<UserEntity> entityGraph =
entityManager.createEntityGraph(UserEntity.class);
entityGraph.addAttributeNodes( "roles" );
Query query = entityManager.createQuery( "SELECT u FROM UserEntity u WHERE u.id =
1" );
query.setMaxResults(1);
query.setHint(EntityGraphType.FETCH.getKey(), entityGraph);
UserEntity userEntity = (UserEntity) query.getSingleResult();
return userEntity.getRoles();
}
getUserRoles returns 2 roles in Hibernate 5.6.15.Final and returns 1 role (which is wrong)
in Hibernate 6.1.7.
(
https://hibernate.atlassian.net/browse/HHH-16408#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16408#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#100221- sha1:57c27f3 )