[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2680) Blobs not updated on Session.merge() for detached instances

Steve Ebersole (JIRA) noreply at atlassian.com
Fri Jun 11 14:10:58 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=37405#action_37405 ] 

Steve Ebersole commented on HHH-2680:
-------------------------------------

BTW, I am not suggesting that this *only* fails on Oracle.  All I am suggesting is to ferret out which databases (dialects) need what approach to handle this.  The solution mentioned here afaiu should work on all because it creates a new BLOB instance.  I guess my point is that perhaps this is overkill on most databases.  For sure I think Dialect should have a hand to play in this.  So maybe something like:
{code}
public Object replace(
        Object original, 
        Object target,
        SessionImplementor session, 
        Object owner, 
        Map copyCache) throws HibernateException {
    if ( original != target && session.getFactory().getDialect().useLobStateTransferOnMerge() ) {
        OutputStream connectedStream = ( (Blob) target ).setBinaryStream( 1L );  // the BLOB just read during the load phase of merge
        InputStream detachedStream = ( (Blob) original ).getBinaryStream();      // the BLOB from the detached state
        copy( detachedStream, connectedStream );  // from, into
        return target;
    }
    else {
        // return the incoming detached state by default.
        return original;
    }
}
{code}

or:
{code}
public Object replace(
        Object original, 
        Object target,
        SessionImplementor session, 
        Object owner, 
        Map copyCache) throws HibernateException {
    if ( original != target && session.getFactory().getDialect().useNewLobsOnMerge() ) {
        Blob detachedBlob = (Blob) original;
        return session.getFactory().getSettings().getJdbcSupport().getLobCreator( session )
                .createBlob( original.getBinaryStream(), original.length() );
    }
    else {
        // return the incoming detached state by default.
        return original;
    }
}
{code}

Or maybe even:
{code}
public Object replace(
        Object original, 
        Object target,
        SessionImplementor session, 
        Object owner, 
        Map copyCache) throws HibernateException {
    if ( original != target && session.getFactory().getDialect().useLobStateTransferOnMerge() ) {
        OutputStream connectedStream = ( (Blob) target ).setBinaryStream( 1L );  // the BLOB just read during the load phase of merge
        InputStream detachedStream = ( (Blob) original ).getBinaryStream();      // the BLOB from the detached state
        copy( detachedStream, connectedStream );  // from, into
        return target;
    }
    else {
        Blob detachedBlob = (Blob) original;
        return session.getFactory().getSettings().getJdbcSupport().getLobCreator( session )
                .createBlob( original.getBinaryStream(), original.length() );
    }
}
{code}

> Blobs not updated on Session.merge() for detached instances
> -----------------------------------------------------------
>
>                 Key: HHH-2680
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2680
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.2, 3.2.4.sp1
>         Environment: Windows XP Prof., Java 1.5_010, HSQLDB 1.8.0
>            Reporter: Timo Thomas
>         Attachments: blobmerge.patch, BlobTest.zip, FileBlob.java, FixedBlobType.java
>
>
> Blob columns are not updated when a detached instance is saved at the session with merge(). See attached TestCase.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list