Hi,
With the following link you might find some help:
http://www.hibernate.org/76.html
(Or search the hibernate website for 'clob string'.)
The class from the above url does a basic usertype mapping between clob and java.lang.String, which is what I use and seems to work for me. The code on that page is not quite correct, b/c it doesn't take NULL values properly into account for instance, but there are some helpful comments at the bottom of the page and it's a useful start.
CLOBs often have a limitation in that they cannot be read after the connection is closed, or even after the JDBC resultset is closed. That makes dealing with CLOBs a bit hard from Hibernate. I don't know how large your CLOBs will typically get, and if it's a problem for you if you have to read them into memory all at once.
Anyways, a snippet of my DDL:
Code:
CREATE TABLE MESSAGE_OUT (
MSGOUTSEQNUM INTEGER NOT NULL generated always as identity (start with 1, increment by 1, no cache),
SFTLCK INTEGER NOT NULL,
TIM TIMESTAMP NOT NULL,
TX_REFPRMSCH VARCHAR ( 200 ),
TX_REF VARCHAR ( 200 ) NOT NULL,
XMLMSGOUT CLOB ( 256k ) NOT NULL,
SECID ROWID NOT NULL GENERATED BY DEFAULT,
CONSTRAINT PK_MESSAGE_OUT7 PRIMARY KEY (MSGOUTSEQNUM)
)
IN JUICE.JCETB1
;
CREATE UNIQUE INDEX PK_MESSAGE_OUT ON MESSAGE_OUT (MSGOUTSEQNUM)
USING STOGROUP JCEGRP1 ERASE NO DEFINE YES BUFFERPOOL BP1 CLOSE YES DEFER NO COPY NO
;
CREATE TYPE 2 UNIQUE INDEX MSGOUTINDX ON MESSAGE_OUT ( SECID )
USING STOGROUP FFIXDB2 ERASE NO DEFINE YES
BUFFERPOOL BP1 CLOSE YES DEFER NO COPY NO;
-- CREATE LOB TABLESPACE MSGOLOB
-- IN G1I4DELV
-- USING STOGROUP FFIXDB2
-- PRIQTY 3000 SECQTY 3000 LOCKMAX 0 CLOSE NO bufferpool BP8K1
-- LOG NO;
CREATE AUXILIARY TABLE G1I4DELV.AUX_MSGOUT
IN G1I4DELV.MSGOLOB
STORES MESSAGE_OUT
COLUMN XMLMSGOUT;
CREATE TYPE 2 UNIQUE INDEX MSGOAUX ON AUX_MSGOUT
USING STOGROUP FFIXDB2 ERASE NO DEFINE YES
BUFFERPOOL BP1 CLOSE YES COPY NO;
And the relevant snippet from my hibernate mapping:
Code:
<hibernate-mapping package="com.unisys.pdg.common.data">
<class name="MessageOut" table="MESSAGE_OUT">
<id
column="MSGOUTSEQNUM"
name="messageOutSequenceNumber"
type="int"
unsaved-value="0"
>
<generator class="native" />
</id>
<version
column="SFTLCK"
name="softLock"
type="int"
unsaved-value="undefined"
/>
<property
column="TIM"
name="timeStamp"
not-null="true"
type="java.sql.Timestamp"
/>
<property
column="TX_REFPRMSCH"
name="txRefSchedule"
not-null="false"
type="string"
/>
<property
column="TX_REF"
name="txRef"
not-null="true"
type="string"
/>
<property
column="XMLMSGOUT"
name="xmlMessageOut"
not-null="true"
type="com.unisys.pdg.common.dao.StringToClobMapper"
>
<meta attribute="actual-type">java.lang.String</meta>
<column
name="XMLMSGOUT"
sql-type="CLOB"
/>
</property>
</class>
</hibernate-mapping>
The type 'com.unisys.pdg.common.dao.StringToClobMapper' is my version of the UserType implementation from the link given atop.
Does this help you anyhow?
cheers,
--Tim
[/u][/list]