-->
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.  [ 8 posts ] 
Author Message
 Post subject: Clobs in same table persisting in wrong DB fields
PostPosted: Tue Aug 30, 2005 10:58 pm 
Newbie

Joined: Sun Jul 31, 2005 8:49 pm
Posts: 7
I am using hibernate 3.0 with an Oracle database. I have a document table that has 3 CLOBs. One called "document", another called "history" and a third called "formattedText". On occassion, when I persist the document object, the value that is in the document property is persisted in the history field and vice-versa. I've put checks in the object's setter and getter methods to catch a programatic error, but it appears as though the CLOBs are being reversed in the hibernate or database tier. Has anyone heard of this?

The CLOB fields are mapped as "text" types. It appears to work 99% of the time. However, there are a couple of places where this has happened. I've also tested with the same dataset over and over and it doesn't happen in the same place, leaving me to believe that there is something else wrong.

Thanks,
Tom


Top
 Profile  
 
 Post subject: More information
PostPosted: Wed Aug 31, 2005 1:34 am 
Newbie

Joined: Sun Jul 31, 2005 8:49 pm
Posts: 7
Just to add more information. I put a break point right before creating the session, beginning the transaction and committing the transaction. The data is correct in the object. Upon committing the object, I look in the database, and the data belonging to the first CLOB is in the second CLOB and vice-versa. The object continues to look right, the database is wrong. Since this doesn't happen with every object that I persist, it doesn't make sense that it would with one. Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 2:03 pm 
Newbie

Joined: Wed Aug 10, 2005 12:12 am
Posts: 8
Location: Washington DC
I have seen the exact same problem with both Hibernate 3.0.5 and Hibernate 3.1 Beta2. We also have a table with more than one CLOB column and they get switched. However, this occurs about the half time. I have these mapped as "text".

Any resolution on your end for this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 2:09 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Could you please post your .hbm.xml and your getters and setters, maybe along with the insertion part of the code?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 2:25 pm 
Newbie

Joined: Wed Aug 10, 2005 12:12 am
Posts: 8
Location: Washington DC
I forgot to mention that I am using Oracle 10g. Here is the mapping. The bolded items are the ones that are flip-flopping.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping
    default-lazy="false"
    auto-import="true"
    default-access="property"
    default-cascade="none"
    package="my.package.application.model.messaging">

    <class
        name="MessageLogEntry"
        table="HL7_TRANSACTION_LOG">

      <id name="identifier" type="big_decimal" column="HL7_TRANSACTION_LOG_ID">
         <generator
            class="my.package.fw.persistent.hibernate.BigSequenceGenerator">
            <param name="sequence">transaction_s</param>
         </generator>
      </id>
      
      <property name="createdOn" type="timestamp" column="RECORD_CREATED_DATE" update="false"/>
      <property name="createdBy"
         type="my.package.fw.persistent.hibernate.AuditUserType"
         column="RECORD_CREATED_BY"/>



        <property
            name="controlIdentifier"
            type="string"
            not-null="true"
            update="false"
            column="MESSAGE_CONTROL_NUMBER"/>

        <property
            name="batchControlIdentifier"
            type="string"
            update="false"
            column="BATCH_CONTROL_NUMBER"/>


        <many-to-one
            name="type"
            class="my.package.application.model.lookup.MessageType"
            outer-join="false"
            cascade="none"
            not-null="true"
            update="false">

            <column name="MESSAGE_TRANSMISSION_TYPE_ID" />
        </many-to-one>

        <property
            name="transmissionDate"
            type="date"
            update="false"
            column="TRANSMISSION_DATE"/>

        <many-to-one
            name="status"
            class="my.package.application.model.lookup.MessageStatus"
            outer-join="false"
            not-null="true">

            <column name="HL7_MESSAGE_STATUS_TYPE_ID" />
        </many-to-one>

[b]          <property
            name="body"
            type="text"
            update="false"
            column="MESSAGE_BODY"/>[/b]

        <property
            name="formattedBody"
            type="text"
            update="false"
            column="FORMATTED_MESSAGE_BODY"/>


        <property
            name="ackDate"
            type="date"
            column="ACK_DATE"/>


        <property
            name="ackType"
            type="string"
            column="ACK_TYPE"/>


        <property
            name="errorText"
            type="string"
            column="ERROR_TEXT"
            length="2000"/>


[b]<property
            name="internalErrorText"
            type="text"
         update="false"
            column="INTERNAL_ERROR_TEXT"/>[/b]

        <many-to-one
            name="initiatingMessage"
            class="MessageLogEntry"
            update="false">

            <column name="REF_HL7_TRANSACTION_LOG_ID" />
        </many-to-one>

        <many-to-one
            name="person"
            class="my.package.application.model.person.Person"
            update="false">

            <column name="PERSON_ID" />
        </many-to-one>

        <property
            name="retransmissionCount"
            type="int"
            update="false"
            column="RETRANSMISSION_COUNT"/>
      
        <property
            name="workloadEvent"
            type="string"
            column="WORKLOAD_EVENT"/>

        <property
            name="workloadReason"
            type="string"
            column="WORKLOAD_REASON"/>
      
        <many-to-one
            name="vaFacility"
            class="my.package.application.model.lookup.VAFacility"
            update="false">

            <column name="STD_INSTITUTION_ID" />
        </many-to-one>
      
    </class>

    <query name="messageLogEntryQuery_ControlIdentifier">
        FROM   MessageLogEntry mle
        WHERE  mle.controlIdentifier = :controlIdentifier
    </query>

    <query name="messageLogEntryQuery_FindByPerson">
        FROM   MessageLogEntry mle
        WHERE  mle.person = :person
    </query>

    <query name="messageLogEntryQuery_FindByAgeAndCount">
        FROM   MessageLogEntry mle
        WHERE  mle.status.code = '03'
         AND   mle.transmissionDate &lt;= sysdate - :age
         AND   mle.retransmissionCount &lt; :maxRetries
    </query>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 6:52 pm 
Newbie

Joined: Sun Jul 31, 2005 8:49 pm
Posts: 7
Thanks shorecode - We have yet to find a solution. I got around it initially by removing all \r\n from the string. This appeared to work, however, once I started inserting a different XML string, it started switching them again. Here is my mapping file:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
    <class
        name="com.presidio.params.PTIDocument"
        table="Document"
    >

        <id
            name="documentId"
            column="documentId"
            type="long"
            unsaved-value="-1"
        >
            <generator class="sequence">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-PTIDocument.xml
                  containing the additional parameters and place it in your merge dir.
              -->
              <param name="sequence">documentId_SEQ</param>
            </generator>
        </id>

        <version
            name="version"
            type="int"
            column="version"
            unsaved-value="negative"
        />

        <property
            name="organizationId"
            type="long"
            column="organizationId"
        />

        <property
            name="key1"
            type="java.lang.String"
            column="key1"
        />

        <property
            name="key2"
            type="java.lang.String"
            column="key2"
        />

        <property
            name="document"
            type="text"
            column="document"
        />

        <property
            name="documentName"
            type="java.lang.String"
            column="documentName"
        />

        <property
            name="documentType"
            type="java.lang.String"
            column="documentType"
        />

        <property
            name="documentOwnerId"
            type="long"
            column="documentOwnerId"
        />

        <property
            name="digitalLock"
            type="java.lang.String"
            column="digitalLock"
        />

        <property
            name="digitalLockDate"
            type="java.lang.String"
            column="digitalLockDate"
        />

        <property
            name="history"
            type="text"
            column="history"
        />

       
        <property
           name="encounterId"
           type="java.lang.Long"
           column="encounterId"
        />

        <property
            name="formattedDocument"
            type="text"
            column="formattedDocument"
        />

        <set name="propertyList" table="propertyList" cascade="all" lazy="false">
           <key column="documentId"/>
           <one-to-many class="com.presidio.params.Property"/>
       </set>

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-PTIDocument.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>
   
</hibernate-mapping>


As you can see, it's pretty straight forward. Nothing special. My getters/setters just get/set a String property. The insert/update is, again, nothing special:


try {
Session session = HibernateUtil.getSession();
HibernateUtil.beginTransaction();
session.save(encounter);
}
catch (Exception ptie) {
throw new PTIHibernateSessionException(PTIException._FATAL, true,
"Unable to save encounter record", ptie);
}

The commit, rollback and session.close are handled outside of the method. That's why they are not there. However, I can walk through my code and the very next statement executed after the save is a commit.

I've turned on log4j and it appears as though it is binding the CLOBs correctly. So, I can't tell if it is somewhere else in hibernate or in the Oracle JDBC layer. I've used this same JDBC driver with Spring and straight JDBC and it works fine. So, I think the involvement of Hibernate here is causing the problem. Anybody else with some thoughts?

Thanks,
Tom


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 11:34 am 
Newbie

Joined: Wed Aug 10, 2005 12:12 am
Posts: 8
Location: Washington DC
I got around this problem by changing my type="text" to now use the Spring ClobStringType class. Using this, I also have to inject a lobHandler into my Spring LocalSessionFactoryBean. This appears to have fixed the issue. Given this, it does sound like there is a problem with the Hibernate support for CLOB's.

When I get a second to breathe over here, I'll create a JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 11:49 am 
Newbie

Joined: Sun Jul 31, 2005 8:49 pm
Posts: 7
Thanks shorecode - I'll give it a try and report back.


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