6 - SQM based on JPA type system
This commit is contained in:
parent
d1b86c2a72
commit
ff59a1301d
|
@ -9,14 +9,16 @@ package org.hibernate.test.cut;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Currency;
|
import java.util.Currency;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.hibernate.query.Query;
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
import org.hibernate.dialect.DB2Dialect;
|
import org.hibernate.dialect.DB2Dialect;
|
||||||
import org.hibernate.dialect.HSQLDialect;
|
import org.hibernate.dialect.HSQLDialect;
|
||||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||||
import org.hibernate.hql.internal.ast.QuerySyntaxException;
|
import org.hibernate.query.Query;
|
||||||
|
import org.hibernate.query.SemanticException;
|
||||||
|
|
||||||
import org.hibernate.testing.DialectChecks;
|
import org.hibernate.testing.DialectChecks;
|
||||||
import org.hibernate.testing.RequiresDialectFeature;
|
import org.hibernate.testing.RequiresDialectFeature;
|
||||||
|
@ -39,183 +41,213 @@ public class CompositeUserTypeTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompositeUserType() {
|
public void testCompositeUserType() {
|
||||||
Session s = openSession();
|
inTransaction(
|
||||||
org.hibernate.Transaction t = s.beginTransaction();
|
s -> {
|
||||||
|
Transaction tran = new Transaction();
|
||||||
Transaction tran = new Transaction();
|
tran.setDescription( "a small transaction" );
|
||||||
tran.setDescription("a small transaction");
|
tran.setValue( new MonetoryAmount( new BigDecimal( 1.5 ), Currency.getInstance( "USD" ) ) );
|
||||||
tran.setValue( new MonetoryAmount( new BigDecimal(1.5), Currency.getInstance("USD") ) );
|
s.persist( tran );
|
||||||
s.persist(tran);
|
|
||||||
|
|
||||||
List result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'USD'").list();
|
|
||||||
assertEquals( result.size(), 1 );
|
|
||||||
tran.getValue().setCurrency( Currency.getInstance("AUD") );
|
|
||||||
result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'AUD'").list();
|
|
||||||
assertEquals( result.size(), 1 );
|
|
||||||
|
|
||||||
if ( !(getDialect() instanceof HSQLDialect) ) {
|
|
||||||
|
|
||||||
result = s.createQuery("from Transaction txn where txn.value = (1.5, 'AUD')").list();
|
|
||||||
assertEquals( result.size(), 1 );
|
|
||||||
result = s.createQuery("from Transaction where value = (1.5, 'AUD')").list();
|
|
||||||
assertEquals( result.size(), 1 );
|
|
||||||
result = s.createQuery( "from Transaction where value != (1.4, 'AUD')" ).list();
|
|
||||||
assertEquals( result.size(), 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
s.delete(tran);
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SkipForDialect ( value = { SybaseASE15Dialect.class }, jiraKey = "HHH-6788" )
|
|
||||||
@SkipForDialect ( value = { DB2Dialect.class }, jiraKey = "HHH-6867" )
|
|
||||||
public void testCustomColumnReadAndWrite() {
|
|
||||||
Session s = openSession();
|
|
||||||
org.hibernate.Transaction t = s.beginTransaction();
|
|
||||||
final BigDecimal AMOUNT = new BigDecimal(73000000d);
|
|
||||||
final BigDecimal AMOUNT_MILLIONS = AMOUNT.divide(new BigDecimal(1000000d));
|
|
||||||
MutualFund f = new MutualFund();
|
|
||||||
f.setHoldings( new MonetoryAmount( AMOUNT, Currency.getInstance("USD") ) );
|
|
||||||
s.persist(f);
|
|
||||||
s.flush();
|
|
||||||
|
|
||||||
// Test value conversion during insert
|
List result = s.createQuery(
|
||||||
BigDecimal amountViaSql = (BigDecimal)s.createSQLQuery("select amount_millions from MutualFund").uniqueResult();
|
"from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'USD'" )
|
||||||
assertEquals(AMOUNT_MILLIONS.doubleValue(), amountViaSql.doubleValue(), 0.01d);
|
.list();
|
||||||
|
assertEquals( result.size(), 1 );
|
||||||
// Test projection
|
tran.getValue().setCurrency( Currency.getInstance( "AUD" ) );
|
||||||
BigDecimal amountViaHql = (BigDecimal)s.createQuery("select f.holdings.amount from MutualFund f").uniqueResult();
|
result = s.createQuery(
|
||||||
assertEquals(AMOUNT.doubleValue(), amountViaHql.doubleValue(), 0.01d);
|
"from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'AUD'" )
|
||||||
|
.list();
|
||||||
// Test restriction and entity load via criteria
|
assertEquals( result.size(), 1 );
|
||||||
BigDecimal one = new BigDecimal(1);
|
|
||||||
f = (MutualFund)s.createCriteria(MutualFund.class)
|
if ( !( getDialect() instanceof HSQLDialect ) ) {
|
||||||
.add(Restrictions.between("holdings.amount", AMOUNT.subtract(one), AMOUNT.add(one)))
|
|
||||||
.uniqueResult();
|
result = s.createQuery( "from Transaction txn where txn.value = (1.5, 'AUD')" ).list();
|
||||||
assertEquals(AMOUNT.doubleValue(), f.getHoldings().getAmount().doubleValue(), 0.01d);
|
assertEquals( result.size(), 1 );
|
||||||
|
result = s.createQuery( "from Transaction where value = (1.5, 'AUD')" ).list();
|
||||||
// Test predicate and entity load via HQL
|
assertEquals( result.size(), 1 );
|
||||||
f = (MutualFund)s.createQuery("from MutualFund f where f.holdings.amount between ?1 and ?2")
|
result = s.createQuery( "from Transaction where value != (1.4, 'AUD')" ).list();
|
||||||
.setBigDecimal(1, AMOUNT.subtract(one))
|
assertEquals( result.size(), 1 );
|
||||||
.setBigDecimal(2, AMOUNT.add(one))
|
}
|
||||||
.uniqueResult();
|
|
||||||
assertEquals(AMOUNT.doubleValue(), f.getHoldings().getAmount().doubleValue(), 0.01d);
|
s.delete( tran );
|
||||||
|
}
|
||||||
s.delete(f);
|
);
|
||||||
t.commit();
|
}
|
||||||
s.close();
|
|
||||||
|
@Test
|
||||||
|
@SkipForDialect(value = { SybaseASE15Dialect.class }, jiraKey = "HHH-6788")
|
||||||
|
@SkipForDialect(value = { DB2Dialect.class }, jiraKey = "HHH-6867")
|
||||||
|
public void testCustomColumnReadAndWrite() {
|
||||||
|
inTransaction(
|
||||||
|
s -> {
|
||||||
|
final BigDecimal AMOUNT = new BigDecimal( 73000000d );
|
||||||
|
final BigDecimal AMOUNT_MILLIONS = AMOUNT.divide( new BigDecimal( 1000000d ) );
|
||||||
|
MutualFund f = new MutualFund();
|
||||||
|
f.setHoldings( new MonetoryAmount( AMOUNT, Currency.getInstance( "USD" ) ) );
|
||||||
|
s.persist( f );
|
||||||
|
s.flush();
|
||||||
|
|
||||||
|
// Test value conversion during insert
|
||||||
|
BigDecimal amountViaSql = (BigDecimal) s.createNativeQuery( "select amount_millions from MutualFund" )
|
||||||
|
.uniqueResult();
|
||||||
|
assertEquals( AMOUNT_MILLIONS.doubleValue(), amountViaSql.doubleValue(), 0.01d );
|
||||||
|
|
||||||
|
// Test projection
|
||||||
|
BigDecimal amountViaHql = (BigDecimal) s.createQuery( "select f.holdings.amount from MutualFund f" )
|
||||||
|
.uniqueResult();
|
||||||
|
assertEquals( AMOUNT.doubleValue(), amountViaHql.doubleValue(), 0.01d );
|
||||||
|
|
||||||
|
// Test restriction and entity load via criteria
|
||||||
|
BigDecimal one = new BigDecimal( 1 );
|
||||||
|
|
||||||
|
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<MutualFund> criteria = criteriaBuilder.createQuery( MutualFund.class );
|
||||||
|
Root<MutualFund> root = criteria.from( MutualFund.class );
|
||||||
|
criteria.where( criteriaBuilder.between(
|
||||||
|
root.get( "holdings" ).get( "amount" ),
|
||||||
|
AMOUNT.subtract( one ),
|
||||||
|
AMOUNT.add( one )
|
||||||
|
) );
|
||||||
|
f = s.createQuery( criteria ).uniqueResult();
|
||||||
|
// f = (MutualFund)s.createCriteria(MutualFund.class)
|
||||||
|
// .add(Restrictions.between("holdings.amount", AMOUNT.subtract(one), AMOUNT.add(one)))
|
||||||
|
// .uniqueResult();
|
||||||
|
assertEquals( AMOUNT.doubleValue(), f.getHoldings().getAmount().doubleValue(), 0.01d );
|
||||||
|
|
||||||
|
// Test predicate and entity load via HQL
|
||||||
|
f = (MutualFund) s.createQuery( "from MutualFund f where f.holdings.amount between ?1 and ?2" )
|
||||||
|
.setParameter( 1, AMOUNT.subtract( one ) )
|
||||||
|
.setParameter( 2, AMOUNT.add( one ) )
|
||||||
|
.uniqueResult();
|
||||||
|
assertEquals( AMOUNT.doubleValue(), f.getHoldings().getAmount().doubleValue(), 0.01d );
|
||||||
|
|
||||||
|
s.delete( f );
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the {@code =} operator on composite types.
|
* Tests the {@code =} operator on composite types.
|
||||||
*/
|
*/
|
||||||
public void testEqualOperator() {
|
public void testEqualOperator() {
|
||||||
final Session s = openSession();
|
inTransaction(
|
||||||
s.getTransaction().begin();
|
s -> {
|
||||||
|
final Transaction txn = new Transaction();
|
||||||
|
txn.setDescription( "foo" );
|
||||||
|
txn.setValue( new MonetoryAmount( new BigDecimal( 42 ), Currency.getInstance( "AUD" ) ) );
|
||||||
|
txn.setTimestamp( new CompositeDateTime( 2014, 8, 23, 14, 35, 0 ) );
|
||||||
|
s.persist( txn );
|
||||||
|
|
||||||
final Transaction txn = new Transaction();
|
final Query q = s.createQuery( "from Transaction where value = :amount" );
|
||||||
txn.setDescription( "foo" );
|
|
||||||
txn.setValue( new MonetoryAmount( new BigDecimal( 42 ), Currency.getInstance( "AUD" ) ) );
|
|
||||||
txn.setTimestamp( new CompositeDateTime( 2014, 8, 23, 14, 35, 0 ) );
|
|
||||||
s.persist( txn );
|
|
||||||
|
|
||||||
final Query q = s.createQuery( "from Transaction where value = :amount" );
|
/* Both amount and currency match. */
|
||||||
|
q.setParameter(
|
||||||
|
"amount",
|
||||||
|
new MonetoryAmount( new BigDecimal( 42 ), Currency.getInstance( "AUD" ) )
|
||||||
|
);
|
||||||
|
assertEquals( 1, q.list().size() );
|
||||||
|
|
||||||
/* Both amount and currency match. */
|
/* Only currency matches. */
|
||||||
q.setParameter( "amount", new MonetoryAmount( new BigDecimal( 42 ), Currency.getInstance( "AUD" ) ) );
|
q.setParameter(
|
||||||
assertEquals( 1, q.list().size() );
|
"amount",
|
||||||
|
new MonetoryAmount( new BigDecimal( 36 ), Currency.getInstance( "AUD" ) )
|
||||||
|
);
|
||||||
|
assertEquals( 0, q.list().size() );
|
||||||
|
|
||||||
/* Only currency matches. */
|
/* Only amount matches. */
|
||||||
q.setParameter( "amount", new MonetoryAmount( new BigDecimal( 36 ), Currency.getInstance( "AUD" ) ) );
|
q.setParameter(
|
||||||
assertEquals( 0, q.list().size() );
|
"amount",
|
||||||
|
new MonetoryAmount( new BigDecimal( 42 ), Currency.getInstance( "EUR" ) )
|
||||||
|
);
|
||||||
|
assertEquals( 0, q.list().size() );
|
||||||
|
|
||||||
/* Only amount matches. */
|
/* None match. */
|
||||||
q.setParameter( "amount", new MonetoryAmount( new BigDecimal( 42 ), Currency.getInstance( "EUR" ) ) );
|
q.setParameter(
|
||||||
assertEquals( 0, q.list().size() );
|
"amount",
|
||||||
|
new MonetoryAmount( new BigDecimal( 76 ), Currency.getInstance( "USD" ) )
|
||||||
|
);
|
||||||
|
assertEquals( 0, q.list().size() );
|
||||||
|
|
||||||
/* None match. */
|
final Query qTimestamp = s.createQuery( "from Transaction where timestamp = :timestamp" );
|
||||||
q.setParameter( "amount", new MonetoryAmount( new BigDecimal( 76 ), Currency.getInstance( "USD" ) ) );
|
|
||||||
assertEquals( 0, q.list().size() );
|
|
||||||
|
|
||||||
final Query qTimestamp = s.createQuery( "from Transaction where timestamp = :timestamp" );
|
/* All matches. */
|
||||||
|
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2014, 8, 23, 14, 35, 0 ) );
|
||||||
|
assertEquals( 1, qTimestamp.list().size() );
|
||||||
|
|
||||||
/* All matches. */
|
/* None matches. */
|
||||||
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2014, 8, 23, 14, 35, 0 ) );
|
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2013, 9, 25, 12, 31, 25 ) );
|
||||||
assertEquals( 1, qTimestamp.list().size() );
|
assertEquals( 0, qTimestamp.list().size() );
|
||||||
|
|
||||||
/* None matches. */
|
/* Year doesn't match. */
|
||||||
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2013, 9, 25, 12, 31, 25 ) );
|
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2013, 8, 23, 14, 35, 0 ) );
|
||||||
assertEquals( 0, qTimestamp.list().size() );
|
assertEquals( 0, qTimestamp.list().size() );
|
||||||
|
|
||||||
/* Year doesn't match. */
|
/* Month doesn't match. */
|
||||||
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2013, 8, 23, 14, 35, 0 ) );
|
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2014, 9, 23, 14, 35, 0 ) );
|
||||||
assertEquals( 0, qTimestamp.list().size() );
|
assertEquals( 0, qTimestamp.list().size() );
|
||||||
|
|
||||||
/* Month doesn't match. */
|
/* Minute doesn't match. */
|
||||||
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2014, 9, 23, 14, 35, 0 ) );
|
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2014, 8, 23, 14, 41, 0 ) );
|
||||||
assertEquals( 0, qTimestamp.list().size() );
|
assertEquals( 0, qTimestamp.list().size() );
|
||||||
|
|
||||||
/* Minute doesn't match. */
|
/* Second doesn't match. */
|
||||||
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2014, 8, 23, 14, 41, 0 ) );
|
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2014, 8, 23, 14, 35, 28 ) );
|
||||||
assertEquals( 0, qTimestamp.list().size() );
|
assertEquals( 0, qTimestamp.list().size() );
|
||||||
|
|
||||||
/* Second doesn't match. */
|
s.delete( txn );
|
||||||
qTimestamp.setParameter( "timestamp", new CompositeDateTime( 2014, 8, 23, 14, 35, 28 ) );
|
}
|
||||||
assertEquals( 0, qTimestamp.list().size() );
|
);
|
||||||
|
|
||||||
s.delete( txn );
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the {@code <>} operator on composite types.
|
* Tests the {@code <>} operator on composite types.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-5946" )
|
@TestForIssue(jiraKey = "HHH-5946")
|
||||||
public void testNotEqualOperator() {
|
public void testNotEqualOperator() {
|
||||||
final Session s = openSession();
|
inTransaction(
|
||||||
s.getTransaction().begin();
|
s -> {
|
||||||
|
final Transaction t1 = new Transaction();
|
||||||
|
t1.setDescription( "foo" );
|
||||||
|
t1.setValue( new MonetoryAmount( new BigDecimal( 178 ), Currency.getInstance( "EUR" ) ) );
|
||||||
|
t1.setTimestamp( new CompositeDateTime( 2014, 8, 23, 14, 23, 0 ) );
|
||||||
|
s.persist( t1 );
|
||||||
|
|
||||||
final Transaction t1 = new Transaction();
|
final Transaction t2 = new Transaction();
|
||||||
t1.setDescription( "foo" );
|
t2.setDescription( "bar" );
|
||||||
t1.setValue( new MonetoryAmount( new BigDecimal( 178 ), Currency.getInstance( "EUR" ) ) );
|
t2.setValue( new MonetoryAmount( new BigDecimal( 1000000 ), Currency.getInstance( "USD" ) ) );
|
||||||
t1.setTimestamp( new CompositeDateTime( 2014, 8, 23, 14, 23, 0 ) );
|
t1.setTimestamp( new CompositeDateTime( 2014, 8, 22, 14, 23, 0 ) );
|
||||||
s.persist( t1 );
|
s.persist( t2 );
|
||||||
|
|
||||||
final Transaction t2 = new Transaction();
|
final Transaction t3 = new Transaction();
|
||||||
t2.setDescription( "bar" );
|
t3.setDescription( "bar" );
|
||||||
t2.setValue( new MonetoryAmount( new BigDecimal( 1000000 ), Currency.getInstance( "USD" ) ) );
|
t3.setValue( new MonetoryAmount( new BigDecimal( 1000000 ), Currency.getInstance( "EUR" ) ) );
|
||||||
t1.setTimestamp( new CompositeDateTime( 2014, 8, 22, 14, 23, 0 ) );
|
t3.setTimestamp( new CompositeDateTime( 2014, 8, 22, 14, 23, 01 ) );
|
||||||
s.persist( t2 );
|
s.persist( t3 );
|
||||||
|
|
||||||
final Transaction t3 = new Transaction();
|
final Query q1 = s.createQuery( "from Transaction where value <> :amount" );
|
||||||
t3.setDescription( "bar" );
|
q1.setParameter(
|
||||||
t3.setValue( new MonetoryAmount( new BigDecimal( 1000000 ), Currency.getInstance( "EUR" ) ) );
|
"amount",
|
||||||
t3.setTimestamp( new CompositeDateTime( 2014, 8, 22, 14, 23, 01 ) );
|
new MonetoryAmount( new BigDecimal( 178 ), Currency.getInstance( "EUR" ) )
|
||||||
s.persist( t3 );
|
);
|
||||||
|
assertEquals( 2, q1.list().size() );
|
||||||
|
|
||||||
final Query q1 = s.createQuery( "from Transaction where value <> :amount" );
|
final Query q2 = s.createQuery( "from Transaction where value <> :amount and description = :str" );
|
||||||
q1.setParameter( "amount", new MonetoryAmount( new BigDecimal( 178 ), Currency.getInstance( "EUR" ) ) );
|
q2.setParameter(
|
||||||
assertEquals( 2, q1.list().size() );
|
"amount",
|
||||||
|
new MonetoryAmount( new BigDecimal( 1000000 ), Currency.getInstance( "USD" ) )
|
||||||
|
);
|
||||||
|
q2.setParameter( "str", "bar" );
|
||||||
|
assertEquals( 1, q2.list().size() );
|
||||||
|
|
||||||
final Query q2 = s.createQuery( "from Transaction where value <> :amount and description = :str" );
|
final Query q3 = s.createQuery( "from Transaction where timestamp <> :timestamp" );
|
||||||
q2.setParameter( "amount", new MonetoryAmount( new BigDecimal( 1000000 ), Currency.getInstance( "USD" ) ) );
|
q3.setParameter( "timestamp", new CompositeDateTime( 2014, 8, 23, 14, 23, 0 ) );
|
||||||
q2.setParameter( "str", "bar" );
|
assertEquals( 2, q3.list().size() );
|
||||||
assertEquals( 1, q2.list().size() );
|
|
||||||
|
|
||||||
final Query q3 = s.createQuery( "from Transaction where timestamp <> :timestamp" );
|
s.delete( t3 );
|
||||||
q3.setParameter( "timestamp", new CompositeDateTime( 2014, 8, 23, 14, 23, 0 ) );
|
s.delete( t2 );
|
||||||
assertEquals( 2, q3.list().size() );
|
s.delete( t1 );
|
||||||
|
}
|
||||||
s.delete( t3 );
|
);
|
||||||
s.delete( t2 );
|
|
||||||
s.delete( t1 );
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,22 +255,18 @@ public class CompositeUserTypeTest extends BaseCoreFunctionalTestCase {
|
||||||
* rather than create a random query.
|
* rather than create a random query.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-5946" )
|
@TestForIssue(jiraKey = "HHH-5946")
|
||||||
@RequiresDialectFeature( value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class )
|
@RequiresDialectFeature(value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class)
|
||||||
public void testLessThanOperator() {
|
public void testLessThanOperator() {
|
||||||
final Session s = openSession();
|
try (Session s = openSession()) {
|
||||||
try {
|
|
||||||
final Query q = s.createQuery( "from Transaction where value < :amount" );
|
final Query q = s.createQuery( "from Transaction where value < :amount" );
|
||||||
q.setParameter( "amount", new MonetoryAmount( BigDecimal.ZERO, Currency.getInstance( "EUR" ) ) );
|
q.setParameter( "amount", new MonetoryAmount( BigDecimal.ZERO, Currency.getInstance( "EUR" ) ) );
|
||||||
q.list();
|
q.list();
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
assertTyping( QuerySyntaxException.class, e.getCause() );
|
assertTyping( SemanticException.class, e.getCause() );
|
||||||
//expected
|
//expected
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -246,22 +274,18 @@ public class CompositeUserTypeTest extends BaseCoreFunctionalTestCase {
|
||||||
* rather than create a random query.
|
* rather than create a random query.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-5946" )
|
@TestForIssue(jiraKey = "HHH-5946")
|
||||||
@RequiresDialectFeature( value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class )
|
@RequiresDialectFeature(value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class)
|
||||||
public void testLessOrEqualOperator() {
|
public void testLessOrEqualOperator() {
|
||||||
final Session s = openSession();
|
try (Session s = openSession()) {
|
||||||
try {
|
|
||||||
final Query q = s.createQuery( "from Transaction where value <= :amount" );
|
final Query q = s.createQuery( "from Transaction where value <= :amount" );
|
||||||
q.setParameter( "amount", new MonetoryAmount( BigDecimal.ZERO, Currency.getInstance( "USD" ) ) );
|
q.setParameter( "amount", new MonetoryAmount( BigDecimal.ZERO, Currency.getInstance( "USD" ) ) );
|
||||||
q.list();
|
q.list();
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
assertTyping( QuerySyntaxException.class, e.getCause() );
|
assertTyping( SemanticException.class, e.getCause() );
|
||||||
//expected
|
//expected
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -269,22 +293,18 @@ public class CompositeUserTypeTest extends BaseCoreFunctionalTestCase {
|
||||||
* rather than create a random query.
|
* rather than create a random query.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-5946" )
|
@TestForIssue(jiraKey = "HHH-5946")
|
||||||
@RequiresDialectFeature( value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class )
|
@RequiresDialectFeature(value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class)
|
||||||
public void testGreaterThanOperator() {
|
public void testGreaterThanOperator() {
|
||||||
final Session s = openSession();
|
try (Session s = openSession()) {
|
||||||
try {
|
|
||||||
final Query q = s.createQuery( "from Transaction where value > :amount" );
|
final Query q = s.createQuery( "from Transaction where value > :amount" );
|
||||||
q.setParameter( "amount", new MonetoryAmount( BigDecimal.ZERO, Currency.getInstance( "EUR" ) ) );
|
q.setParameter( "amount", new MonetoryAmount( BigDecimal.ZERO, Currency.getInstance( "EUR" ) ) );
|
||||||
q.list();
|
q.list();
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
assertTyping( QuerySyntaxException.class, e.getCause() );
|
assertTyping( SemanticException.class, e.getCause() );
|
||||||
//expected
|
//expected
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -292,22 +312,18 @@ public class CompositeUserTypeTest extends BaseCoreFunctionalTestCase {
|
||||||
* rather than create a random query.
|
* rather than create a random query.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-5946" )
|
@TestForIssue(jiraKey = "HHH-5946")
|
||||||
@RequiresDialectFeature( value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class )
|
@RequiresDialectFeature(value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class)
|
||||||
public void testGreaterOrEqualOperator() {
|
public void testGreaterOrEqualOperator() {
|
||||||
final Session s = openSession();
|
try (Session s = openSession()) {
|
||||||
try {
|
|
||||||
final Query q = s.createQuery( "from Transaction where value >= :amount" );
|
final Query q = s.createQuery( "from Transaction where value >= :amount" );
|
||||||
q.setParameter( "amount", new MonetoryAmount( BigDecimal.ZERO, Currency.getInstance( "USD" ) ) );
|
q.setParameter( "amount", new MonetoryAmount( BigDecimal.ZERO, Currency.getInstance( "USD" ) ) );
|
||||||
q.list();
|
q.list();
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
assertTyping( QuerySyntaxException.class, e.getCause() );
|
assertTyping( SemanticException.class, e.getCause() );
|
||||||
//expected
|
//expected
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import javax.persistence.ManyToOne;
|
||||||
|
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.engine.spi.QueryParameters;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.jdbc.Work;
|
import org.hibernate.jdbc.Work;
|
||||||
import org.hibernate.loader.plan.exec.process.spi.ResultSetProcessor;
|
import org.hibernate.loader.plan.exec.process.spi.ResultSetProcessor;
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.engine.spi.QueryParameters;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.jdbc.Work;
|
import org.hibernate.jdbc.Work;
|
||||||
import org.hibernate.loader.plan.exec.process.spi.ResultSetProcessor;
|
import org.hibernate.loader.plan.exec.process.spi.ResultSetProcessor;
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.hibernate.Session;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.id.PostInsertIdentifierGenerator;
|
|
||||||
|
|
||||||
import org.hibernate.testing.DialectCheck;
|
import org.hibernate.testing.DialectCheck;
|
||||||
import org.hibernate.testing.RequiresDialectFeature;
|
import org.hibernate.testing.RequiresDialectFeature;
|
|
@ -37,8 +37,6 @@ import org.hibernate.dialect.function.SQLFunction;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
Loading…
Reference in New Issue