1 package org.hibernate.test.cut; 3 4 import java.math.BigDecimal ; 5 import java.util.Currency ; 6 import java.util.List ; 7 8 import junit.framework.Test; 9 import junit.framework.TestSuite; 10 11 import org.hibernate.Session; 12 import org.hibernate.dialect.HSQLDialect; 13 import org.hibernate.dialect.Oracle9Dialect; 14 import org.hibernate.test.TestCase; 15 16 19 public class CompositeUserTypeTest extends TestCase { 20 21 public CompositeUserTypeTest(String str) { 22 super(str); 23 } 24 25 public void testCompositeUserType() { 26 Session s = openSession(); 27 org.hibernate.Transaction t = s.beginTransaction(); 28 29 Transaction tran = new Transaction(); 30 tran.setDescription("a small transaction"); 31 tran.setValue( new MonetoryAmount( new BigDecimal (1.5), Currency.getInstance("USD") ) ); 32 s.persist(tran); 33 34 List result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'USD'").list(); 35 assertEquals( result.size(), 1 ); 36 tran.getValue().setCurrency( Currency.getInstance("AUD") ); 37 result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'AUD'").list(); 38 assertEquals( result.size(), 1 ); 39 40 if ( !(getDialect() instanceof HSQLDialect) && ! (getDialect() instanceof Oracle9Dialect) ) { 41 42 result = s.createQuery("from Transaction txn where txn.value = (1.5, 'AUD')").list(); 43 assertEquals( result.size(), 1 ); 44 result = s.createQuery("from Transaction where value = (1.5, 'AUD')").list(); 45 assertEquals( result.size(), 1 ); 46 47 } 48 49 s.delete(tran); 50 t.commit(); 51 s.close(); 52 } 53 54 55 protected String [] getMappings() { 56 return new String [] { "cut/Transaction.hbm.xml" }; 57 } 58 59 public static Test suite() { 60 return new TestSuite(CompositeUserTypeTest.class); 61 } 62 63 } 64 65 | Popular Tags |