Hi,
I have a bytea column which I want to return as a base64 string. If I run the following sql query in postgreSQL (7.4.1):
Select encode(a.artist_photo2, 'base64') as artist_photo2 from artisttbl a where a.artist_id=46
I get:
artist_photo2
/9j/4AAQSkZJ.......more base64.......
If I run the same query in hibernate(Version 2.1.1) I get:
10:36:14,689 DEBUG SessionImpl:528 - opened session
10:36:14,691 DEBUG JDBCTransaction:37 - begin
10:36:14,695 DEBUG JDBCTransaction:41 - current autocommit status:false
10:36:14,723 DEBUG SessionImpl:3614 - SQL query: Select encode({a}.artist_photo2, 'base64') as {a.ArtistPhoto2} from artisttbl {a} where {a}.artist_id=:artist_id
10:36:14,732 DEBUG SessionImpl:2193 - flushing session
10:36:14,737 DEBUG SessionImpl:2321 - Flushing entities and processing referenced collections
10:36:14,739 DEBUG SessionImpl:2664 - Processing unreferenced collections
10:36:14,740 DEBUG SessionImpl:2678 - Scheduling collection removes/(re)creates/updates
10:36:14,742 DEBUG SessionImpl:2217 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
10:36:14,756 DEBUG SessionImpl:2222 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
10:36:14,758 DEBUG SessionImpl:1745 - Dont need to execute flush
10:36:14,760 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
10:36:14,762 DEBUG SQL:223 - Select encode(a.artist_photo2, 'base64') as artist_p5_0_ from artisttbl a where a.artist_id=? limit ?
Hibernate: Select encode(a.artist_photo2, 'base64') as artist_p5_0_ from artisttbl a where a.artist_id=? limit ?
10:36:14,763 DEBUG BatcherImpl:227 - preparing statement
10:36:14,795 DEBUG Loader:196 - processing result set
10:36:14,815 DEBUG JDBCExceptionReporter:36 - SQL Exception
org.postgresql.util.PSQLException: The column name artist_id0_ not found.
my hibernate code is:
transaction = session.beginTransaction();
//Get Artist image
String queryString = "Select encode({a}.artist_photo2, 'base64') as " + photo2 + " as {a.ArtistPhoto2} from artisttbl {a} where {a}.artist_id=:artist_id";
artist = (String)session.createSQLQuery(queryString,"a",Artist.class)
.setParameter("artist_id",artID)
.setMaxResults(1)
.uniqueResult();
transaction.commit();
my map is:
<hibernate-mapping package="test">
<class name="Artist" table="artisttbl">
<id name="ID" column="artist_id" type="integer" unsaved-value="0">
<generator class="sequence">
<param name="sequence">artist_seq_id</param>
</generator>
</id>
<property name="ArtistName" column="artist_name" type="string" not-null="true"/>
<property name="ArtistInfo" column="artist_info" type="string"/>
<property name="ArtistPhoto1" column="artist_photo1" type="binary"/>
<property name="ArtistPhoto2" column="artist_photo2" type="binary"/>
<property name="ArtistPhoto3" column="artist_photo3" type="binary"/>
</class>
</hibernate-mapping>
What obvious point am I overlooking here?
many thanks in advance
|