i'm trying to get a blob-stream with hibernate
public InputStream getMediaData(MediaEntity media) throws SQLException{
media = load(media.getID());
DataBlob blob = media.getData();
Blob blobData = blob.getData();
return blobData.getBinaryStream();
}
but when calling "getBinaryStream" it throws
org.postgresql.util.PSQLException: This connection has been closed.
at org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:714)
at org.postgresql.jdbc2.AbstractJdbc2Connection.getAutoCommit(AbstractJdbc2Connection.java:680)
at org.postgresql.fastpath.Fastpath.fastpath(Fastpath.java:74)
at org.postgresql.fastpath.Fastpath.fastpath(Fastpath.java:114)
at org.postgresql.fastpath.Fastpath.getInteger(Fastpath.java:126)
at org.postgresql.largeobject.LargeObject.<init>(LargeObject.java:93)
at org.postgresql.largeobject.LargeObject.copy(LargeObject.java:98)
at org.postgresql.jdbc2.AbstractJdbc2BlobClob.getBinaryStream(AbstractJdbc2BlobClob.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.engine.jdbc.SerializableBlobProxy.invoke(SerializableBlobProxy.java:73)
but it can't be a transaction problem, it's the same function
any ideas?
or does he try to use the connection which was active while doing the
LobCreator lobCreator = Hibernate.getLobCreator(session);
Blob blob = lobCreator.createBlob(input, media.getLength());
?
THE MEDIAENTITY:
@Entity
public class MediaEntity {
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
private Long mediaID;
@ManyToOne(cascade = CascadeType.ALL)
DataBlob data;
long length;
public Long getMediaID() {
return mediaID;
}
public void setMediaID(Long mediaID) {
this.mediaID = mediaID;
}
public DataBlob getData() {
return data;
}
public void setData(DataBlob data) {
this.data = data;
}
public long getLength() {
return length;
}
public void setLength(long length) {
this.length = length;
}
}
THE DATABLOB:
@Entity
public class DataBlob {
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Lob
private Blob data;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Blob getData() {
return data;
}
public void setData(Blob data) {
this.data = data;
}
}