I have been reading BLOBs (type lo
in my PostgreSQL database) in my entities so far with no trouble:
@Entity
@Getter @Setter
public class MyEntity {
@Id
private Long id;
@Lob
private Blob file;
}
And the following override in the dialect:
@Override
public boolean equivalentTypes(int type1, int type2) {
// The 'lo' type is an alias for 'oid', which is typed as DISTINCT
return super.equivalentTypes(type1, type2) ||
(type1 == Types.BLOB && type2 == Types.DISTINCT) ||
(type1 == Types.DISTINCT && type2 == Types.BLOB);
}
Now I want to start creating new ones, but I need to account for the large object ACLs. After any new BLOB is crated, I need to execute a query such as:
GRANT SELECT ON LARGE OBJECT 12345 TO reader_role;
The obvious way I can think to do it is with a post-save hook on every entity that has a @Lob
field, but how can you execute SQL in the same transaction using that?
Is there a better way to do it at the type-level? An existing hook or an interface to override? I suspect Hibernate (and JPA in general) has no concept of blobs existing independently of an entity, because that only happens AFAIK in PostgreSQL.