Large Objects may not be used in auto-commit mode
A large object can be stored in several records, that's why you have to use a transaction. All records are correct or nothing at all.
https://www.postgresql.org/docs/current/static/largeobjects.html
Instead of using @Transactional
, all I did for this issue was to update this column in PostgreSQL DB from oid
type to bytea
type and added @Type
for the @Lob
field.
i.e.
ALTER TABLE person DROP COLUMN image;ALTER TABLE person ADD COLUMN image bytea;
And changed
@Lobprivate byte[] image;
To
@Lob@Type(type = "org.hibernate.type.ImageType")private byte[] image;
If you can, create a intermediate Entity between MyClass and file property for instance.Something like:
@Entity@Table(name="myobjects")public class MyClass { @OneToOne(cascade = ALL, fetch = LAZY) private File file;}@Entity@Table(name="file")public class File { @Lob byte[] file;}
You can't use @Lob and fetch type Lazy. It doesnt work. You must have a a intermediate class.