[hibernate-commits] Hibernate SVN: r20067 - in core/trunk/testsuite/src/test/java/org/hibernate/test: lob and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Jul 26 12:47:21 EDT 2010


Author: steve.ebersole at jboss.com
Date: 2010-07-26 12:47:20 -0400 (Mon, 26 Jul 2010)
New Revision: 20067

Added:
   core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobEntity.java
   core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobTest.java
Modified:
   core/trunk/testsuite/src/test/java/org/hibernate/test/lob/LongByteArrayTest.java
   core/trunk/testsuite/src/test/java/org/hibernate/test/lob/MaterializedBlobTest.java
Log:
HHH-5400 - Blob persistence fails with Hibernate 3.6.0-SNAPSHOT, works with 3.5.3-Final


Added: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobEntity.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobEntity.java	                        (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobEntity.java	2010-07-26 16:47:20 UTC (rev 20067)
@@ -0,0 +1,79 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, 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.annotations.lob;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+ at Entity
+public class MaterializedBlobEntity {
+	@Id()
+	@GeneratedValue(strategy = GenerationType.SEQUENCE)
+	private Long id;
+
+	private String name;
+
+	@Lob
+	private byte[] theBytes;
+
+	public MaterializedBlobEntity() {
+	}
+
+	public MaterializedBlobEntity(String name, byte[] theBytes) {
+		this.name = name;
+		this.theBytes = theBytes;
+	}
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public byte[] getTheBytes() {
+		return theBytes;
+	}
+
+	public void setTheBytes(byte[] theBytes) {
+		this.theBytes = theBytes;
+	}
+}

Added: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobTest.java	                        (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobTest.java	2010-07-26 16:47:20 UTC (rev 20067)
@@ -0,0 +1,80 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, 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.annotations.lob;
+
+import java.util.Arrays;
+
+import org.hibernate.Session;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.testing.junit.DialectChecks;
+import org.hibernate.testing.junit.RequiresDialectFeature;
+import org.hibernate.type.MaterializedBlobType;
+import org.hibernate.type.Type;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+ at RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
+public class MaterializedBlobTest extends TestCase {
+	@Override
+	protected void configure(Configuration cfg) {
+		super.configure( cfg );
+		cfg.setProperty( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
+	}
+
+	@Override
+	protected Class<?>[] getAnnotatedClasses() {
+		return new Class<?>[] { MaterializedBlobEntity.class };
+	}
+
+	public void testTypeSelection() {
+		int index = sfi().getEntityPersister( MaterializedBlobEntity.class.getName() ).getEntityMetamodel().getPropertyIndex( "theBytes" );
+		Type  type = sfi().getEntityPersister( MaterializedBlobEntity.class.getName() ).getEntityMetamodel().getProperties()[index].getType();
+		assertEquals( MaterializedBlobType.INSTANCE, type );
+	}
+
+	public void testSaving() {
+		byte[] testData = "test data".getBytes();
+
+		Session session = openSession();
+		session.beginTransaction();
+		MaterializedBlobEntity entity = new MaterializedBlobEntity( "test", testData );
+		session.save( entity );
+		session.getTransaction().commit();
+		session.close();
+
+		session = openSession();
+		session.beginTransaction();
+		entity = ( MaterializedBlobEntity ) session.get( MaterializedBlobEntity.class, entity.getId() );
+		assertTrue( Arrays.equals( testData, entity.getTheBytes() ) );
+		session.delete( entity );
+		session.getTransaction().commit();
+		session.close();
+	}
+}

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/lob/LongByteArrayTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/lob/LongByteArrayTest.java	2010-07-26 14:05:03 UTC (rev 20066)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/lob/LongByteArrayTest.java	2010-07-26 16:47:20 UTC (rev 20067)
@@ -88,6 +88,27 @@
 		s.close();
 	}
 
+	public void testSaving() {
+		byte[] value = buildRecursively( ARRAY_SIZE, true );
+
+		Session s = openSession();
+		s.beginTransaction();
+		LongByteArrayHolder entity = new LongByteArrayHolder();
+		entity.setLongByteArray( value );
+		s.persist( entity );
+		s.getTransaction().commit();
+		s.close();
+
+		s = openSession();
+		s.beginTransaction();
+		entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
+		assertEquals( ARRAY_SIZE, entity.getLongByteArray().length );
+		assertEquals( value, entity.getLongByteArray() );
+		s.delete( entity );
+		s.getTransaction().commit();
+		s.close();
+	}
+
 	private byte[] buildRecursively(int size, boolean on) {
 		byte[] data = new byte[size];
 		data[0] = mask( on );

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/lob/MaterializedBlobTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/lob/MaterializedBlobTest.java	2010-07-26 14:05:03 UTC (rev 20066)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/lob/MaterializedBlobTest.java	2010-07-26 16:47:20 UTC (rev 20067)
@@ -50,6 +50,16 @@
 		return new FunctionalTestClassTestSuite( MaterializedBlobTest.class );
 	}
 
+	@Override
+	public void testBoundedLongByteArrayAccess() {
+		super.testBoundedLongByteArrayAccess();
+	}
+
+	@Override
+	public void testSaving() {
+		super.testSaving();
+	}
+
 	public boolean appliesTo(Dialect dialect) {
 		if ( ! dialect.supportsExpectedLobUsagePattern() ) {
 			reportSkip( "database/driver does not support expected LOB usage pattern", "LOB support" );



More information about the hibernate-commits mailing list