Overview
A JavaEE 5 project is being developed using Netbeans 6.1, integrated Glassfish application server and Hibernate 3.2 as the JPA provider interacting with a PostgreSQL 8.2 database. Having recently moved over from JBoss, I’m very happy with Hibernate and chose to use it over the default Toplink provider, so I’ve added support for it to Glassfish.
One of the fields to be persisted is a byte[] in Java which needs to be mapped to a bytea database field. The Entity classes were generated using the New->Entity Classes From Database… feature in Netbeans which generated the following code for the byte array:
@Entity
public class UnitData {
...
<auto generated code>
...
@Lob
@Column(name = "telemetry_data",nullable = false)
private byte[] telemetryData;
...
<auto generated code>
...
}
All this seems fine. The code compiles successfully and deploys successfully.
Problem
When trying to persist the UnitData bean, Hibernate throws a org.hibernate.exception.SQLGrammarException, even though everything appears to be fine in the code.
Solution
Hibernate doesn’t like the @Lob over the byte[] field. Just remove it.
Other
I recommend upgrading Hibernate. This problem was discovered when using Hibernate Core 3.2, Annotatations 3.3.1 and EntityManager 3.3.2. All packages were stable (.GA) releases. I’ve picked up another annoying problem with Hibernate and am currently using the latest development releases of Hibernate 3.4 (.CR1). I don’t know if the .CR1 packages fix the @Lob problem, but they do fix another batch update problem I was having.


I am using jboss seam …and richfaces .. for file upload..
I used bytea for storing image into daatabase … in postgres 8.3
I got exception
is of type bytea but expression is of type Integer…
Then i change to OID datatype same as bolb in oracle…. .
This is my java class :
private byte[] brandingLogo;
@Column(name = “branding_logo”
@Lob
public byte[] getBrandingLogo() {
return this.brandingLogo;
}
public void setBrandingLogo(byte[] brandingLogo) {
this.brandingLogo = brandingLogo;
}
public void fileUploadListener(UploadEvent event) throws Exception{
upload = event.getUploadItem();
if (upload.isTempFile()) {
file = upload.getFile();
} else {
ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write(upload.getData());
}
}
public UploadItem getUpload() {
return upload;
}
public void setUpload(UploadItem upload) {
this.upload = upload;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
But when i store it…
id | branding_logo
—+—————
1 | 206533
2 | 206534
3 | 206535
9 | 206543
7 | 206537
How can i identify that is store the image… in database..
I guess it store sequence number…
Please help me…
shashi