I am using spring boot and hibernate. as cache i am using redis and GenericJackson2JsonRedisSerializer.
When I try to retrieve my entity from cache iI am getting:
Failure getting from cache: user_entity. Could not read JSON: failed to lazily initialize a collection: could not initialize proxy - no Session (through reference chain: com.avid.identity.service.entity.User["identities"]
I was trying to change Lazy on Eager, it did not help. Please see entity below.
@Getter
@Setter
@ToString(of = {"id"})
@EqualsAndHashCode(of = {"id"})
@Entity
@NoArgsConstructor
@Table(name = "user", schema = "identity")
public class User {
@Id
@GeneratedValue(generator = "uuid4")
@GenericGenerator(name = "UUID", strategy = "uuid4")
@Column(columnDefinition = "CHAR(36)")
private UUID id;
@Fetch(FetchMode.JOIN)
@JoinColumn(name = "last_authentication_id", referencedColumnName = "id")
@OneToOne(fetch = FetchType.LAZY, orphanRemoval = true)
private AuthenticationEvent lastAuthentication;
@Fetch(FetchMode.JOIN)
@JoinTable(name = "user_identities", joinColumns = {
@JoinColumn(name = "user_id")}, inverseJoinColumns = {
@JoinColumn(name = "user_identity_id")})
@OneToMany(fetch = FetchType.LAZY, orphanRemoval = true)
private List<Identity> identities;
@Fetch(FetchMode.JOIN)
@JoinTable(name = "user_roles", joinColumns = {
@JoinColumn(name = "user_id")}, inverseJoinColumns = {
@JoinColumn(name = "role_id")})
@OneToMany(fetch = FetchType.LAZY)
private List<Role> roles;
@Fetch(FetchMode.JOIN)
@JoinColumn(name = "tenant_id", referencedColumnName = "id")
@OneToOne(fetch = FetchType.LAZY)
private Tenant tenant;
Please help. Thank You