-->
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.  [ 2 posts ] 
Author Message
 Post subject: Oracle LOB's the easy way returns null
PostPosted: Tue Mar 15, 2005 5:18 am 
Newbie

Joined: Mon Mar 14, 2005 12:33 pm
Posts: 6
Hibernate version:2.1.7

Mapping documents:
[code]<class name="Message" table="MESSAGE">
<id name="messageid" column="MESSAGEID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">SEQ_MESSAGE</param>
</generator>
</id>

<property name="messagecontent" column="MESSAGECONTENT" type="java.lang.String" />
</class>
[code]


Code between sessionFactory.openSession() and session.close():
[code]
Session session = HibernateSessionFactory.currentSession();
String querystring = "SELECT msg FROM Message as msg where messageid= :msgid";
Query query = session.createQuery(querystring);
query.setLong("msgid", messageid.longValue());
List list = query.list();
if (list.size() > 0) {
Message message = (Message) list.get(0);
strResult = message.getMessage();
}
[code]

Name and version of the database you are using:
Oracle 9.0.2.5

I read this forum about clob's and Oracle and was amazed when I read that using the OCI driver and the new oracle 10 driver (ojdbc14.jar) would make your life easy. So I changed my configuration and was amazed to see I could easily store a large XML message as a string into my CLOB column.
But then the next step is retrieving that column again. Unfortunately I do not seem to get that working.
The column is mapped to a java.lang.String, as indicated in this forum. That works for storing the column, but when the object is retrieved, I keep getting a null value, although the database shows the value is not null!


Abstract generated class:
[code]
public abstract class AbstractRismessage
implements Serializable
{
/** The composite primary key value. */
private java.lang.Long messageid;

/** The value of the simple xmlmessage property. */
private java.lang.String messagecontent;


public java.lang.String getMessagecontent()
{
return this.messagecontent;
}
public void setMessagecontent(java.lang.String content)
{
this.messagecontent = content;
}
}

[code]


The hybernate configuration was changed to:
[code]
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.jdbc.use_streams_for_binary"> true</property>
<property name="SetBigStringTryClob">true</property>
[code]

And I am using the OCI driver.

So using the the setMessagecontent method works like a dream after changing my hybernate configuration. But using the getMessagecontent method always returns a null.

Does anyone have an idea? I'd rather not implement the Interceptor stuff if I don't need to.

Thanks for any suggestions...


Top
 Profile  
 
 Post subject: For LOB support set mapping to text
PostPosted: Thu Mar 17, 2005 3:34 pm 
Newbie

Joined: Mon Mar 14, 2005 12:33 pm
Posts: 6
This is very easy to fix. I should have seen it in one of the other subjects!

When using a CLOB and setting a large string, do not map the column to java.lang.String, but use the Hibernate text type. So:

<class name="Message" table="MESSAGE">
<id name="messageid" column="MESSAGEID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">SEQ_MESSAGE</param>
</generator>
</id>

<property name="messagecontent" column="MESSAGECONTENT" type="text" />
</class>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.