| In the meanwhile until my fix is not applied, here is my version of a path for PostgreSQL 94. The class must be passed with the Hibernate property hibernate.dialect. Note: Instead of extending PostgreSQL94Dialect the real patch would directly apply the above mentioned lines {{ {{ if ( original == null && target == null ) { return null; } if ( original == target) { return original; } }} directly to the Dialect class of Hibernate. {{package your.package; import org.hibernate.dialect.LobMergeStrategy; import org.hibernate.dialect.PostgreSQL94Dialect; import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionImplementor; import java.sql.Blob; import java.sql.Clob; import java.sql.NClob; import java.sql.SQLException; /**
- Sets a LobMergeStrategy not to merge Blobs if they are the same. Old implementation is coming from {@link org.hibernate.dialect.Dialect#NEW_LOCATOR_LOB_MERGE_STRATEGY}
is duplicating
- also the blob which leads to a fast growing database because also if the binary data is not changed it will be duplicated.
*/ public class FixedPostgreSQL94Dialect extends PostgreSQL94Dialect {
/**
- Merge strategy based on creating a new LOB locator.
- <p>
- This one returns the original and not a copy if the original and target Blobs are identical.
- </p>
*/ protected static final LobMergeStrategy FIXED_NEW_LOCATOR_LOB_MERGE_STRATEGY = new LobMergeStrategy() { @Override public Blob mergeBlob(Blob original, Blob target, SessionImplementor session)
Unknown macro: { if (original == null && target == null) { return null; } if (original == target) { return original; } if (original == null) { return null; } if (target == null) { return NEW_LOCATOR_LOB_MERGE_STRATEGY.mergeBlob(original, target, session); } // forward to streaming implementation return STREAM_XFER_LOB_MERGE_STRATEGY.mergeBlob(original, target, session); }
@Override public Clob mergeClob(Clob original, Clob target, SessionImplementor session) { if (original == null && target == null) { return null; } if (original == target) { return original; } try { final LobCreator lobCreator = session.getFactory().getServiceRegistry().getService(JdbcServices.class).getLobCreator(session); return original == null ? lobCreator.createClob("") : lobCreator.createClob(original.getCharacterStream(), original.length()); } catch (SQLException e) { throw session.getFactory().getServiceRegistry().getService(JdbcServices.class).getSqlExceptionHelper().convert(e, "unable to merge CLOB data"); } } @Override public NClob mergeNClob(NClob original, NClob target, SessionImplementor session) { if (original == null && target == null) { return null; } if (original == target) { return original; } try { final LobCreator lobCreator = session.getFactory().getServiceRegistry().getService(JdbcServices.class).getLobCreator(session); return original == null ? lobCreator.createNClob("") : lobCreator.createNClob(original.getCharacterStream(), original.length()); } catch (SQLException e) { throw session.getFactory().getServiceRegistry().getService(JdbcServices.class).getSqlExceptionHelper().convert(e, "unable to merge NCLOB data"); } } }; public LobMergeStrategy getLobMergeStrategy() { return FIXED_NEW_LOCATOR_LOB_MERGE_STRATEGY; } } }} |