-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: @Lob of type byte[] is mapped to PostgreSQL's oid type
PostPosted: Sat Apr 08, 2006 12:46 pm 
Newbie

Joined: Fri Apr 22, 2005 3:39 pm
Posts: 18
Hello!

Could somebody help me with this:
I'm getting strange DDL create table script for PostgreSQL dialect while using annotations. @Lob of type byte[] is mapped to PostgreSQL's oid type. The CRUD operations fail: I'm reading not the data I write.

An explanation or a workaround is welcome!

Thank you!

Hibernate version:
Hibernate 3.1.2
Annotations 3.1 beta8


Mapping documents:
@Entity
public class Data {

private Long id;

private byte[] bytes;

public Data() {
super();
this.bytes = new byte[0];
}

public Data(byte[] bytes) {
super();
this.bytes = bytes;
}

@Id
@GeneratedValue
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Lob
public byte[] getBytes() {
return bytes;
}

public void setBytes(byte[] bytes) {
this.bytes = bytes;
}

}



hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.username=postgres
hibernate.connection.password=postgres
hibernate.connection.url=jdbc:postgresql://localhost/test
hibernate.show_sql=true
hibernate.format_sql=true

Code:
ac = new AnnotationConfiguration();
ac.setProperties(properties);
ac.addAnnotatedClass(Data.class);

Dialect dialect = DialectFactory.buildDialect(properties.get(
"hibernate.dialect").toString());
String[] createDDL = ac.generateSchemaCreationScript(dialect);


Name and version of the database you are using:
PostgreSQL 8.0

The generated SQL (show_sql=true):
create table Data (id int8 not null, bytes oid, primary key (id))
create sequence hibernate_sequence


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 09, 2006 1:45 am 
Newbie

Joined: Fri Apr 22, 2005 3:39 pm
Posts: 18
I have solved the problem. Just in case someone gets interested:
1) oid is the correct type for blob object. It's just a reference to it.
2) use jdbc driver newer than 8.0, it has a bug in it that causes data loss in blob

Michael.


Top
 Profile  
 
 Post subject: Re:
PostPosted: Thu Jul 01, 2010 6:46 pm 
Beginner
Beginner

Joined: Mon Jun 28, 2010 1:02 pm
Posts: 21
Michael Baranov wrote:
I have solved the problem. Just in case someone gets interested:
1) oid is the correct type for blob object. It's just a reference to it.
2) use jdbc driver newer than 8.0, it has a bug in it that causes data loss in blob

Michael.


What was the actual problem? I'm using PosgreSQL 8.4, byte[] data type in Java, but I cannot persist my class. What can be wrong? Should I use java.Sql.Blob in my Java code? Or use additional annotations besides @Lob?
Here's my problem:
https://forum.hibernate.org/viewtopic.php?f=1&t=1005584


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.