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

View File

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

View File

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