-
1. Re: Forcing bytea for Blobs in Postresql
rhodan76 Dec 10, 2008 7:01 AM (in response to getaceres)Hello,
we annotate all our lob-columns in the entity with the @javax.persistence.Lob annotation and let the persistence provider decide, what he will create in the specific database. So you are not tied a specific database handling of lobs.
Example:public String description; @Column @Lob public String getDescription() { return this.description; }
-
2. Re: Forcing bytea for Blobs in Postresql
getaceres Dec 10, 2008 7:11 AM (in response to getaceres)I've done that, this is my code:
@Lob protected byte[] content;
However, for that field Toplink assumes that the underlying type is bytea, while Hibernate assumes that it is oid. So basically, every one of them is defaulting to a different way to store a Blob of the two allowed by PostgreSQL. -
3. Re: Forcing bytea for Blobs in Postresql
rhodan76 Dec 10, 2008 10:15 AM (in response to getaceres)"getaceres" wrote:
... Hibernate assumes that it is oid...
No Problem, you have to redefine the default Postgres Dialect, that hibernate uses. For a better understanding: when you look in org.hibernate.dialect.PostgresDialect you will see:registerColumnType( Types.BLOB, "oid" );
You must extend these dialect with your own Implementation, and simple re-register the Types.BLOB to whatever you want (and postgres accepts). Then you must tell hibernate, to use your own dialect for postgres (either in hibernate.cfg or persistence.xml):<property name="hibernate.dialect" value="my.com.xyz.OwnPostgresDialect" />
-
4. Re: Forcing bytea for Blobs in Postresql
getaceres Dec 10, 2008 12:50 PM (in response to getaceres)It's not so easy, I think. That would make the validation to succeed but reading a bytea or reading an oid is completely different.
When using oid, the blob is saved in another table, so reading it will involve reading in streaming from a table. It's a completely different system. As I'm using byte[] for my JPA type, I expect Hibernate to read the blob when I need it, so it must go to the blob table and read the content marked by the oid field. It's only a foreing key.
On the other hand, using bytea means saving the blob in the same table as it is defined, so reading it will mean reading from the table that the Entity represents as a field and not using streaming.
As the reading method is completely different, I don't think that changing the registerColumnType call will be enough, but I can be mistaken. The type registration changes also the way that the column is read? I mean, treating a column as content data or as a foreing key, depending on the type.