HHH-5400 - Blob persistence fails with Hibernate 3.6.0-SNAPSHOT, works with 3.5.3-Final

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@20067 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-07-26 16:47:20 +00:00
parent 01ba27d700
commit 33f05cd487
4 changed files with 190 additions and 0 deletions

View File

@ -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
*/
@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;
}
}

View File

@ -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
*/
@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();
}
}

View File

@ -88,6 +88,27 @@ public abstract class LongByteArrayTest extends DatabaseSpecificFunctionalTestCa
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 );

View File

@ -50,6 +50,16 @@ public class MaterializedBlobTest extends LongByteArrayTest {
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" );