Jpa load Lob field reports Unable to access lob stream exception

there is a main table that needs to load a child table, and a field in the child table is Lob to hold the picture.
now the Lob field has data. When I query the main table data, I will report an exception
Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream

an error was reported when obtaining a User through securityUserRepository.findByName ("XXX") .
because it returns data to the interface, the Location part of the SecurityUser cannot be changed to lazy loading, so how to change it? which kind-hearted person will show you?
Thank you!

the following is the main part of the code. SecurityUser is the main table and Location is the child table:
SecurityUser

public class SecurityUser implements Serializable {

    private static final long serialVersionUID = 57212890345839147L;

    @Id
    private String id;

    @Basic(optional = false)
    @Column(length = 100, unique = true)
    @NaturalId
    private String name;
    
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "SECURITY_USER_LOCATION", joinColumns = { @JoinColumn(name = "users_id") }, inverseJoinColumns = { @JoinColumn(name = "location_id") })
    private Set<Location> locations = new HashSet<>();
  }

Location

public class Location implements Serializable {

    private static final long serialVersionUID = -4750805696249599768L;

    @Id
    @Column(name = "ID")
    private String id;
    
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "IMAGE", nullable = true)
    @JsonSerialize(using = ByteSerializer.class)
    private byte[] image;
    
   }

SecurityUserRepository

@Repository
public interface SecurityUserRepository extends JpaRepository<SecurityUser, String> {

    public SecurityUser findByName(String name);
}
Apr.21,2022

finds the method on its own, just add a transaction to the called method. The specific reason for doing this is not clear, ask the great god to answer!

Menu