Search in sources :

Example 1 with ImageHolder

use of org.hibernate.test.sql.hand.ImageHolder in project hibernate-orm by hibernate.

the class NativeSQLQueriesTest method testImageTypeInSQLQuery.

@SkipForDialect(value = AbstractHANADialect.class, comment = "On HANA, this returns a blob for the image column which doesn't get mapped to a byte[]")
@Test
public void testImageTypeInSQLQuery() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    byte[] photo = buildLongByteArray(15000, true);
    ImageHolder holder = new ImageHolder(photo);
    s.persist(holder);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    byte[] photoRead = (byte[]) s.createSQLQuery(getPhotosSQL()).uniqueResult();
    assertTrue(Arrays.equals(photo, photoRead));
    s.delete(holder);
    t.commit();
    s.close();
}
Also used : ImageHolder(org.hibernate.test.sql.hand.ImageHolder) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 2 with ImageHolder

use of org.hibernate.test.sql.hand.ImageHolder in project hibernate-orm by hibernate.

the class CustomSQLTestSupport method testImageProperty.

@Test
public void testImageProperty() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    byte[] photo = buildLongByteArray(15000, true);
    ImageHolder holder = new ImageHolder(photo);
    s.save(holder);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    holder = (ImageHolder) s.get(ImageHolder.class, holder.getId());
    assertTrue(Arrays.equals(photo, holder.getPhoto()));
    photo = buildLongByteArray(15000, false);
    holder.setPhoto(photo);
    s.save(holder);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    holder = (ImageHolder) s.get(ImageHolder.class, holder.getId());
    assertTrue(Arrays.equals(photo, holder.getPhoto()));
    s.delete(holder);
    t.commit();
    s.close();
}
Also used : ImageHolder(org.hibernate.test.sql.hand.ImageHolder) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Session (org.hibernate.Session)2 Transaction (org.hibernate.Transaction)2 ImageHolder (org.hibernate.test.sql.hand.ImageHolder)2 Test (org.junit.Test)2 SkipForDialect (org.hibernate.testing.SkipForDialect)1