Xset (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Bean Validation (
https://hibernate.atlassian.net/browse/BVAL?atlOrigin=eyJpIjoiOWMyN2M2NTU...
) / Bug (
https://hibernate.atlassian.net/browse/BVAL-757?atlOrigin=eyJpIjoiOWMyN2M...
) BVAL-757 (
https://hibernate.atlassian.net/browse/BVAL-757?atlOrigin=eyJpIjoiOWMyN2M...
) Lazy fetch type doesn't work for identical objects (
https://hibernate.atlassian.net/browse/BVAL-757?atlOrigin=eyJpIjoiOWMyN2M...
)
Change By: Xset (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
There is User Entity:
{code:java}@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
...
@ Column(nullable = false)
@ OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
public Set<UserPermission> permissions;
}{code}
There is Permission Entity:
{code:java}@Entity
@Table(name = "user_permissions", indexes = {@Index(unique = true, columnList =
"id")})
public class UserPermission {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", referencedColumnName = "id")
public User user;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_user_id", referencedColumnName = "id")
public User targetUser;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "other_entity", referencedColumnName = "id")
public OtherEntity otherEntity;
}{code}
I use this code to fetch User Entity:
{code:java}... get session
... open transaction
// fetching user
final User user = session.find(User.class, id);
// fetching permissions
final Set<UserPermission> userPermissions = user.permissions;
// foreach permissions
// HIBERNATE FETCHES HERE targetUser AND EVERYTHING CONNECTED TO THIS ENTITY, LOOKS LIKE
FetchType.EAGER
for (UserPermission permission: userPermissions) {
// there is no code
}
... close transaction{code}
Look at the comment in code above:
{code:java}// HIBERNATE FETCHES HERE targetUser AND EVERYTHING CONNECTED TO THIS ENTITY,
LOOKS LIKE FetchType.EAGER{code}
It means, that without any calls to targetUser, hibernate fetches it. That's really
strange. This behavior really slows down performance of my application.
My assumption: Hibernate just can't proxy two similar objects in one entity (i mean,
user and targetUser have the same class, hibernate cannot proxy both objects and thats why
it fetches targetUser immediately)
How to solve this problem? Any suggestions?
(
https://hibernate.atlassian.net/browse/BVAL-757#add-comment?atlOrigin=eyJ...
) Add Comment (
https://hibernate.atlassian.net/browse/BVAL-757#add-comment?atlOrigin=eyJ...
)
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#100140- sha1:33445dc )