HHH-18480 ClassCastException when updating a Blob with Oracle

This commit is contained in:
Andrea Boriero 2024-09-12 11:57:24 +02:00 committed by Andrea Boriero
parent 6cc292e9d3
commit d8ad674e7f
3 changed files with 27 additions and 28 deletions

View File

@ -131,11 +131,8 @@ public class BlobJavaType extends AbstractClassJavaType<Blob> {
return (X) DataHelper.extractBytes( value.getBinaryStream() ); return (X) DataHelper.extractBytes( value.getBinaryStream() );
} }
} }
else if (Blob.class.isAssignableFrom( type )) { else if ( Blob.class.isAssignableFrom( type ) ) {
final Blob blob = value instanceof WrappedBlob return (X) getOrCreateBlob( value, options );
? ( (WrappedBlob) value ).getWrappedBlob()
: getOrCreateBlob(value, options);
return (X) blob;
} }
} }
catch ( SQLException e ) { catch ( SQLException e ) {
@ -146,13 +143,16 @@ public class BlobJavaType extends AbstractClassJavaType<Blob> {
} }
private Blob getOrCreateBlob(Blob value, WrapperOptions options) throws SQLException { private Blob getOrCreateBlob(Blob value, WrapperOptions options) throws SQLException {
if(options.getDialect().useConnectionToCreateLob()) { if ( value instanceof WrappedBlob ) {
if(value.length() == 0) { value = ( (WrappedBlob) value ).getWrappedBlob();
}
if ( options.getDialect().useConnectionToCreateLob() ) {
if ( value.length() == 0 ) {
// empty Blob // empty Blob
return options.getLobCreator().createBlob(new byte[0]); return options.getLobCreator().createBlob( new byte[0] );
} }
else { else {
return options.getLobCreator().createBlob(value.getBytes(1, (int) value.length())); return options.getLobCreator().createBlob( value.getBytes( 1, (int) value.length() ) );
} }
} }
else { else {

View File

@ -104,11 +104,8 @@ public class ClobJavaType extends AbstractClassJavaType<Clob> {
return (X) LobStreamDataHelper.extractString( value.getCharacterStream() ); return (X) LobStreamDataHelper.extractString( value.getCharacterStream() );
} }
} }
else if (Clob.class.isAssignableFrom( type )) { else if ( Clob.class.isAssignableFrom( type ) ) {
final Clob clob = value instanceof WrappedClob return (X) getOrCreateClob( value, options );
? ( (WrappedClob) value ).getWrappedClob()
: getOrCreateClob(value, options);
return (X) clob;
} }
else if ( String.class.isAssignableFrom( type ) ) { else if ( String.class.isAssignableFrom( type ) ) {
if (value instanceof ClobImplementer) { if (value instanceof ClobImplementer) {
@ -129,13 +126,16 @@ public class ClobJavaType extends AbstractClassJavaType<Clob> {
} }
private Clob getOrCreateClob(Clob value, WrapperOptions options) throws SQLException { private Clob getOrCreateClob(Clob value, WrapperOptions options) throws SQLException {
if(options.getDialect().useConnectionToCreateLob()) { if ( value instanceof WrappedClob ) {
if(value.length() == 0) { value = ( (WrappedClob) value ).getWrappedClob();
}
if ( options.getDialect().useConnectionToCreateLob() ) {
if ( value.length() == 0 ) {
// empty Clob // empty Clob
return options.getLobCreator().createClob(""); return options.getLobCreator().createClob( "" );
} }
else { else {
return options.getLobCreator().createClob(value.getSubString(1, (int) value.length())); return options.getLobCreator().createClob( value.getSubString( 1, (int) value.length() ) );
} }
} }
else { else {

View File

@ -103,11 +103,8 @@ public class NClobJavaType extends AbstractClassJavaType<NClob> {
return (X) new CharacterStreamImpl( DataHelper.extractString( value.getCharacterStream() ) ); return (X) new CharacterStreamImpl( DataHelper.extractString( value.getCharacterStream() ) );
} }
} }
else if (NClob.class.isAssignableFrom( type )) { else if ( NClob.class.isAssignableFrom( type ) ) {
final NClob nclob = value instanceof WrappedNClob return (X) getOrCreateNClob( value, options );
? ( (WrappedNClob) value ).getWrappedNClob()
: getOrCreateNClob(value, options);
return (X) nclob;
} }
} }
catch ( SQLException e ) { catch ( SQLException e ) {
@ -118,13 +115,16 @@ public class NClobJavaType extends AbstractClassJavaType<NClob> {
} }
private NClob getOrCreateNClob(NClob value, WrapperOptions options) throws SQLException { private NClob getOrCreateNClob(NClob value, WrapperOptions options) throws SQLException {
if(options.getDialect().useConnectionToCreateLob()) { if ( value instanceof WrappedNClob ) {
if(value.length() == 0) { value = ( (WrappedNClob) value ).getWrappedNClob();
}
if ( options.getDialect().useConnectionToCreateLob() ) {
if ( value.length() == 0 ) {
// empty NClob // empty NClob
return options.getLobCreator().createNClob(""); return options.getLobCreator().createNClob( "" );
} }
else { else {
return options.getLobCreator().createNClob(value.getSubString(1, (int) value.length())); return options.getLobCreator().createNClob( value.getSubString( 1, (int) value.length() ) );
} }
} }
else { else {
@ -132,7 +132,6 @@ public class NClobJavaType extends AbstractClassJavaType<NClob> {
} }
} }
public <X> NClob wrap(X value, WrapperOptions options) { public <X> NClob wrap(X value, WrapperOptions options) {
if ( value == null ) { if ( value == null ) {
return null; return null;