diff --git a/core/src/main/java/org/hibernate/Hibernate.java b/core/src/main/java/org/hibernate/Hibernate.java index 7fea791475..b5e594d5c9 100644 --- a/core/src/main/java/org/hibernate/Hibernate.java +++ b/core/src/main/java/org/hibernate/Hibernate.java @@ -453,7 +453,8 @@ public final class Hibernate { * @param bytes a byte array * @param session The session in which the {@link Blob} will be used. * @return the Blob - * @deprecated Use {@link LobHelper#createBlob(byte[])} instead. + * @deprecated Use {@link LobHelper#createBlob(byte[])} instead on the {@link LobHelper} obtained from + * {@link Session#getLobHelper()} */ public static Blob createBlob(byte[] bytes, Session session) { return getLobCreator( session ).createBlob( bytes ); @@ -553,7 +554,8 @@ public final class Hibernate { * @param string The string data * @param session The session in which the {@link Clob} will be used. * @return The created {@link Clob} - * @deprecated Use {@link LobHelper#createClob(String)} instead + * @deprecated Use {@link LobHelper#createClob(String)} instead on the {@link LobHelper} obtained from + * {@link Session#getLobHelper()} */ @Deprecated public static Clob createClob(String string, Session session) { diff --git a/core/src/main/java/org/hibernate/context/ThreadLocalSessionContext.java b/core/src/main/java/org/hibernate/context/ThreadLocalSessionContext.java index 594c8e8679..9b5e2e06ae 100644 --- a/core/src/main/java/org/hibernate/context/ThreadLocalSessionContext.java +++ b/core/src/main/java/org/hibernate/context/ThreadLocalSessionContext.java @@ -73,11 +73,12 @@ import org.hibernate.engine.SessionFactoryImplementor; public class ThreadLocalSessionContext implements CurrentSessionContext { private static final Logger log = LoggerFactory.getLogger( ThreadLocalSessionContext.class ); - private static final Class[] SESS_PROXY_INTERFACES = new Class[] { + private static final Class[] SESSION_PROXY_INTERFACES = new Class[] { org.hibernate.classic.Session.class, org.hibernate.engine.SessionImplementor.class, org.hibernate.jdbc.JDBCContext.Context.class, - org.hibernate.event.EventSource.class + org.hibernate.event.EventSource.class, + org.hibernate.engine.jdbc.LobCreationContext.class }; /** @@ -182,7 +183,7 @@ public class ThreadLocalSessionContext implements CurrentSessionContext { TransactionProtectionWrapper wrapper = new TransactionProtectionWrapper( session ); Session wrapped = ( Session ) Proxy.newProxyInstance( Session.class.getClassLoader(), - SESS_PROXY_INTERFACES, + SESSION_PROXY_INTERFACES, wrapper ); // yick! need this for proper serialization/deserialization handling... diff --git a/testsuite/src/test/java/org/hibernate/test/connections/HibernateCreateBlobFailedCase.java b/testsuite/src/test/java/org/hibernate/test/connections/HibernateCreateBlobFailedCase.java new file mode 100644 index 0000000000..969d793fad --- /dev/null +++ b/testsuite/src/test/java/org/hibernate/test/connections/HibernateCreateBlobFailedCase.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.connections; + +import org.hibernate.Hibernate; +import org.hibernate.Session; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.testing.junit.functional.FunctionalTestCase; + +import java.sql.Blob; +import java.sql.Clob; +import java.sql.SQLException; + +/** + * Test originally developed to verify and fix HHH-5550 + * + * @author Steve Ebersole + */ +public class HibernateCreateBlobFailedCase extends FunctionalTestCase { + public HibernateCreateBlobFailedCase(String string) { + super( string ); + } + + public String[] getMappings() { + return new String[] { "connections/Silly.hbm.xml" }; + } + + @Override + public void configure(Configuration cfg) { + super.configure( cfg ); + cfg.setProperty( Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread" ); + } + + public void testLobCreation() throws SQLException { + Session session = sfi().getCurrentSession(); + session.beginTransaction(); + Blob blob = Hibernate.getLobCreator( session ).createBlob( new byte[] {} ); + blob.free(); + blob = Hibernate.createBlob( new byte[] {}, session ); + blob.free(); + Clob clob = Hibernate.getLobCreator( session ).createClob( "Steve" ); + clob.free(); + clob = Hibernate.createClob( "Steve", session ); + clob.free(); + session.getTransaction().commit(); + assertFalse( session.isOpen() ); + } +} \ No newline at end of file