mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-08 20:24:46 +00:00
HHH-10691 - Fix other PostgreSQL test failures after HEM integration
This commit is contained in:
parent
25c75eed6f
commit
d54b7ad50f
@ -36,6 +36,7 @@
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.SkipForDialects;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
import org.junit.Test;
|
||||
import junit.framework.Assert;
|
||||
|
||||
@ -69,7 +70,7 @@ protected void addConfigOptions(Map options) {
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-7192" )
|
||||
@TestForIssue(jiraKey = "HHH-7192")
|
||||
public void testTypedManipulationQueryError() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
@ -79,6 +80,12 @@ public void testTypedManipulationQueryError() {
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
//expected
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@ -86,6 +93,13 @@ public void testTypedManipulationQueryError() {
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
//expected
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,6 +107,7 @@ public void testTypedManipulationQueryError() {
|
||||
public void testPagedQuery() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
item = new Item( "Computer", "Apple II" );
|
||||
@ -105,14 +120,20 @@ public void testPagedQuery() throws Exception {
|
||||
q.setParameter( "itemName", "%" );
|
||||
q.setFirstResult( 1 );
|
||||
q.setMaxResults( 1 );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullPositionalParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
Query q = em.createQuery( "from Item i where i.intVal=?" );
|
||||
@ -128,14 +149,20 @@ public void testNullPositionalParameter() throws Exception {
|
||||
q.setParameter( 0, null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullPositionalParameterParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
Query q = em.createQuery( "from Item i where i.intVal=?" );
|
||||
@ -144,10 +171,12 @@ public void testNullPositionalParameterParameter() throws Exception {
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPosition() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getParameterType() {
|
||||
return Integer.class;
|
||||
@ -166,14 +195,20 @@ public Class getParameterType() {
|
||||
q.setParameter( p, null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullPositionalParameterParameterIncompatible() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
Query q = em.createQuery( "from Item i where i.intVal=?" );
|
||||
@ -182,10 +217,12 @@ public void testNullPositionalParameterParameterIncompatible() throws Exception
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPosition() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getParameterType() {
|
||||
return Long.class;
|
||||
@ -204,14 +241,20 @@ public Class getParameterType() {
|
||||
q.setParameter( p, null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullNamedParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
Query q = em.createQuery( "from Item i where i.intVal=:iVal" );
|
||||
@ -227,14 +270,20 @@ public void testNullNamedParameter() throws Exception {
|
||||
q.setParameter( "iVal", null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullNamedParameterParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
Query q = em.createQuery( "from Item i where i.intVal=:iVal" );
|
||||
@ -243,10 +292,12 @@ public void testNullNamedParameterParameter() throws Exception {
|
||||
public String getName() {
|
||||
return "iVal";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPosition() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getParameterType() {
|
||||
return Integer.class;
|
||||
@ -264,14 +315,20 @@ public Class getParameterType() {
|
||||
q.setParameter( p, null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullNamedParameterParameterIncompatible() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
Query q = em.createQuery( "from Item i where i.intVal=:iVal" );
|
||||
@ -280,10 +337,12 @@ public void testNullNamedParameterParameterIncompatible() throws Exception {
|
||||
public String getName() {
|
||||
return "iVal";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPosition() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getParameterType() {
|
||||
return Long.class;
|
||||
@ -301,9 +360,14 @@ public Class getParameterType() {
|
||||
q.setParameter( p, null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialects(
|
||||
@ -316,6 +380,7 @@ public Class getParameterType() {
|
||||
public void testNativeQueryNullPositionalParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
// native queries don't seem to flush by default ?!?
|
||||
@ -333,15 +398,27 @@ public void testNativeQueryNullPositionalParameter() throws Exception {
|
||||
q.setParameter( 0, null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10161" )
|
||||
@TestForIssue(jiraKey = "HHH-10161")
|
||||
@SkipForDialects(
|
||||
value = {
|
||||
@SkipForDialect(value = PostgreSQL9Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint"),
|
||||
@SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
|
||||
}
|
||||
)
|
||||
public void testNativeQueryNullPositionalParameterParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
// native queries don't seem to flush by default ?!?
|
||||
@ -352,10 +429,12 @@ public void testNativeQueryNullPositionalParameterParameter() throws Exception {
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPosition() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getParameterType() {
|
||||
return Integer.class;
|
||||
@ -374,9 +453,14 @@ public Class getParameterType() {
|
||||
q.setParameter( p, null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialects(
|
||||
@ -389,6 +473,7 @@ public Class getParameterType() {
|
||||
public void testNativeQueryNullNamedParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
// native queries don't seem to flush by default ?!?
|
||||
@ -406,15 +491,27 @@ public void testNativeQueryNullNamedParameter() throws Exception {
|
||||
q.setParameter( "iVal", null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10161" )
|
||||
@TestForIssue(jiraKey = "HHH-10161")
|
||||
@SkipForDialects(
|
||||
value = {
|
||||
@SkipForDialect(value = PostgreSQL9Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint"),
|
||||
@SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
|
||||
}
|
||||
)
|
||||
public void testNativeQueryNullNamedParameterParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
// native queries don't seem to flush by default ?!?
|
||||
@ -425,10 +522,12 @@ public void testNativeQueryNullNamedParameterParameter() throws Exception {
|
||||
public String getName() {
|
||||
return "iVal";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPosition() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getParameterType() {
|
||||
return Integer.class;
|
||||
@ -446,14 +545,20 @@ public Class getParameterType() {
|
||||
q.setParameter( p, null );
|
||||
results = q.getResultList();
|
||||
assertEquals( 1, results.size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggregationReturnType() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
item = new Item( "Computer", "Apple II" );
|
||||
@ -461,14 +566,20 @@ public void testAggregationReturnType() throws Exception {
|
||||
Query q = em.createQuery( "select count(i) from Item i where i.name like :itemName" );
|
||||
q.setParameter( "itemName", "%" );
|
||||
assertTrue( q.getSingleResult() instanceof Long );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeExpression() throws Exception {
|
||||
final EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
final Employee employee = new Employee( "Lukasz", 100.0 );
|
||||
em.persist( employee );
|
||||
final Contractor contractor = new Contractor( "Kinga", 100.0, "Microsoft" );
|
||||
@ -477,23 +588,30 @@ public void testTypeExpression() throws Exception {
|
||||
final List result = q.getResultList();
|
||||
assertNotNull( result );
|
||||
assertEquals( Arrays.asList( employee ), result );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH_7407" )
|
||||
@TestForIssue(jiraKey = "HHH_7407")
|
||||
public void testMultipleParameterLists() throws Exception {
|
||||
final Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
final Item item2 = new Item( "Computer", "Dell computer" );
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
em.persist( item2 );
|
||||
assertTrue( em.contains( item ) );
|
||||
em.getTransaction().commit();
|
||||
|
||||
|
||||
List<String> names = Arrays.asList( item.getName() );
|
||||
Query q = em.createQuery( "select item from Item item where item.name in :names or item.name in :names2" );
|
||||
q.setParameter( "names", names );
|
||||
@ -503,7 +621,8 @@ public void testMultipleParameterLists() throws Exception {
|
||||
assertEquals( 1, result.size() );
|
||||
|
||||
List<String> descrs = Arrays.asList( item.getDescr() );
|
||||
q = em.createQuery( "select item from Item item where item.name in :names and ( item.descr is null or item.descr in :descrs )" );
|
||||
q = em.createQuery(
|
||||
"select item from Item item where item.name in :names and ( item.descr is null or item.descr in :descrs )" );
|
||||
q.setParameter( "names", names );
|
||||
q.setParameter( "descrs", descrs );
|
||||
result = q.getResultList();
|
||||
@ -514,16 +633,24 @@ public void testMultipleParameterLists() throws Exception {
|
||||
em.remove( em.getReference( Item.class, item.getName() ) );
|
||||
em.remove( em.getReference( Item.class, item2.getName() ) );
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH_8949" )
|
||||
@TestForIssue(jiraKey = "HHH_8949")
|
||||
public void testCacheStoreAndRetrieveModeParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
try {
|
||||
Query query = em.createQuery( "select item from Item item" );
|
||||
|
||||
query.getHints().clear();
|
||||
@ -543,14 +670,23 @@ public void testCacheStoreAndRetrieveModeParameter() throws Exception {
|
||||
assertEquals( CacheStoreMode.REFRESH, query.getHints().get( "javax.persistence.cache.storeMode" ) );
|
||||
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJpaPositionalParameters() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
try {
|
||||
Query query = em.createQuery( "from Item item where item.name =?1 or item.descr = ?1" );
|
||||
Parameter p1 = query.getParameter( 1 );
|
||||
Assert.assertNotNull( p1 );
|
||||
@ -559,8 +695,17 @@ public void testJpaPositionalParameters() {
|
||||
Assert.assertNull( p1.getPosition() );
|
||||
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterList() throws Exception {
|
||||
@ -569,6 +714,7 @@ public void testParameterList() throws Exception {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
em.persist( item2 );
|
||||
assertTrue( em.contains( item ) );
|
||||
@ -608,9 +754,17 @@ public void testParameterList() throws Exception {
|
||||
em.remove( result.get( 0 ) );
|
||||
em.remove( result.get( 1 ) );
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterListInExistingParens() throws Exception {
|
||||
@ -619,6 +773,7 @@ public void testParameterListInExistingParens() throws Exception {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
em.persist( item2 );
|
||||
assertTrue( em.contains( item ) );
|
||||
@ -661,9 +816,17 @@ public void testParameterListInExistingParens() throws Exception {
|
||||
em.remove( result.get( 0 ) );
|
||||
em.remove( result.get( 1 ) );
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscapeCharacter() throws Exception {
|
||||
@ -672,6 +835,7 @@ public void testEscapeCharacter() throws Exception {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
em.persist( item2 );
|
||||
assertTrue( em.contains( item ) );
|
||||
@ -685,9 +849,17 @@ public void testEscapeCharacter() throws Exception {
|
||||
int deleted = em.createQuery( "delete from Item" ).executeUpdate();
|
||||
assertEquals( 2, deleted );
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeQueryByEntity() {
|
||||
@ -695,6 +867,7 @@ public void testNativeQueryByEntity() {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
assertTrue( em.contains( item ) );
|
||||
em.getTransaction().commit();
|
||||
@ -710,9 +883,16 @@ public void testNativeQueryByEntity() {
|
||||
assertEquals( "Micro$oft mouse", item.getDescr() );
|
||||
em.remove( item );
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -721,26 +901,38 @@ public void testNativeQueryByResultSet() {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
assertTrue( em.contains( item ) );
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.getTransaction().begin();
|
||||
item = (Item) em.createNativeQuery( "select name as itemname, descr as itemdescription from Item", "getItem" )
|
||||
item = (Item) em.createNativeQuery(
|
||||
"select name as itemname, descr as itemdescription from Item",
|
||||
"getItem"
|
||||
)
|
||||
.getSingleResult();
|
||||
assertNotNull( item );
|
||||
assertEquals( "Micro$oft mouse", item.getDescr() );
|
||||
em.remove( item );
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitPositionalParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Wallet w = new Wallet();
|
||||
w.setBrand( "Lacoste" );
|
||||
w.setModel( "Minimic" );
|
||||
@ -760,14 +952,23 @@ public void testExplicitPositionalParameter() throws Exception {
|
||||
assertEquals( 0, query.getResultList().size() );
|
||||
em.remove( w );
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemporalTypeBinding() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
try {
|
||||
Query query = em.createQuery( "select w from " + Wallet.class.getName() + " w where w.marketEntrance = :me" );
|
||||
Parameter parameter = query.getParameter( "me", Date.class );
|
||||
assertEquals( parameter.getParameterType(), Date.class );
|
||||
@ -777,7 +978,16 @@ public void testTemporalTypeBinding() {
|
||||
query.setParameter( "me", new GregorianCalendar(), TemporalType.DATE );
|
||||
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -785,6 +995,7 @@ public void testTemporalTypeBinding() {
|
||||
public void testPositionalParameterForms() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Wallet w = new Wallet();
|
||||
w.setBrand( "Lacoste" );
|
||||
w.setModel( "Minimic" );
|
||||
@ -814,13 +1025,23 @@ public void testPositionalParameterForms() throws Exception {
|
||||
|
||||
em.remove( w );
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPositionalParameterWithUserError() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Wallet w = new Wallet();
|
||||
w.setBrand( "Lacoste" );
|
||||
w.setModel( "Minimic" );
|
||||
@ -835,7 +1056,7 @@ public void testPositionalParameterWithUserError() throws Exception {
|
||||
jpaQuery.setParameter( 2, "Expensive" );
|
||||
fail( "Should fail due to a user error in parameters" );
|
||||
}
|
||||
catch( IllegalArgumentException e ) {
|
||||
catch (IllegalArgumentException e) {
|
||||
// success, expected
|
||||
}
|
||||
|
||||
@ -846,19 +1067,24 @@ public void testPositionalParameterWithUserError() throws Exception {
|
||||
hqlQuery.setParameter( 2, "Expensive" );
|
||||
fail( "Should fail due to a user error in parameters" );
|
||||
}
|
||||
catch( IllegalArgumentException e ) {
|
||||
catch (IllegalArgumentException e) {
|
||||
// success expected
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeQuestionMarkParameter() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Wallet w = new Wallet();
|
||||
w.setBrand( "Lacoste" );
|
||||
w.setModel( "Minimic" );
|
||||
@ -872,8 +1098,18 @@ public void testNativeQuestionMarkParameter() throws Exception {
|
||||
assertNotNull( w );
|
||||
em.remove( w );
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeQueryWithPositionalParameter() {
|
||||
@ -881,6 +1117,7 @@ public void testNativeQueryWithPositionalParameter() {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
assertTrue( em.contains( item ) );
|
||||
em.getTransaction().commit();
|
||||
@ -898,15 +1135,23 @@ public void testNativeQueryWithPositionalParameter() {
|
||||
assertEquals( "Micro$oft mouse", item.getDescr() );
|
||||
em.remove( item );
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistinct() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.createQuery( "delete Item" ).executeUpdate();
|
||||
em.createQuery( "delete Distributor" ).executeUpdate();
|
||||
Distributor d1 = new Distributor();
|
||||
@ -928,14 +1173,20 @@ public void testDistinct() throws Exception {
|
||||
//item = (Item) distinctResult.get( 0 );
|
||||
assertTrue( Hibernate.isInitialized( item.getDistributors() ) );
|
||||
assertEquals( 2, item.getDistributors().size() );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNull() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Distributor d1 = new Distributor();
|
||||
d1.setName( "Fnac" );
|
||||
Distributor d2 = new Distributor();
|
||||
@ -961,10 +1212,14 @@ public void testIsNull() throws Exception {
|
||||
result = q.getResultList();
|
||||
assertEquals( 1, result.size() );
|
||||
//item = (Item) distinctResult.get( 0 );
|
||||
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateQuery() {
|
||||
@ -972,6 +1227,7 @@ public void testUpdateQuery() {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
assertTrue( em.contains( item ) );
|
||||
|
||||
@ -986,10 +1242,13 @@ public void testUpdateQuery() {
|
||||
item = em.find( Item.class, item.getName() );
|
||||
assertEquals( "Logitech Mouse", item.getDescr() );
|
||||
em.remove( item );
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
|
||||
}
|
||||
em.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -998,10 +1257,11 @@ public void testUnavailableNamedQuery() throws Exception {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
try {
|
||||
em.createNamedQuery( "wrong name" );
|
||||
fail("Wrong named query should raise an exception");
|
||||
fail( "Wrong named query should raise an exception" );
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
//success
|
||||
@ -1018,8 +1278,13 @@ public void testUnavailableNamedQuery() throws Exception {
|
||||
"entity should not of been saved to database since IllegalArgumentException should of" +
|
||||
"caused transaction to be marked for rollback only", em.find( Item.class, item.getName() )
|
||||
);
|
||||
}
|
||||
finally {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1028,6 +1293,7 @@ public void testTypedNamedNativeQuery() {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
assertTrue( em.contains( item ) );
|
||||
em.getTransaction().commit();
|
||||
@ -1040,13 +1306,23 @@ public void testTypedNamedNativeQuery() {
|
||||
em.remove( item );
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypedScalarQueries() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
em.persist( item );
|
||||
assertTrue( em.contains( item ) );
|
||||
@ -1061,7 +1337,8 @@ public void testTypedScalarQueries() {
|
||||
assertEquals( 2, itemTuple.getElements().size() );
|
||||
assertEquals( String.class, itemTuple.get( 0 ).getClass() );
|
||||
assertEquals( String.class, itemTuple.get( 1 ).getClass() );
|
||||
Item itemView = em.createQuery( "select new Item(i.name,i.descr) from Item i", Item.class ).getSingleResult();
|
||||
Item itemView = em.createQuery( "select new Item(i.name,i.descr) from Item i", Item.class )
|
||||
.getSingleResult();
|
||||
assertNotNull( itemView );
|
||||
assertEquals( "Micro$oft mouse", itemView.getDescr() );
|
||||
itemView = em.createNamedQuery( "query-construct", Item.class ).getSingleResult();
|
||||
@ -1069,23 +1346,36 @@ public void testTypedScalarQueries() {
|
||||
assertEquals( "Micro$oft mouse", itemView.getDescr() );
|
||||
em.remove( item );
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-10269")
|
||||
@TestForIssue(jiraKey = "HHH-10269")
|
||||
public void testFailingNativeQuery() {
|
||||
final EntityManager entityManager = getOrCreateEntityManager();
|
||||
// Tests that Oracle does not run out of cursors.
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
try {
|
||||
entityManager.createNativeQuery("Select 1 from NotExistedTable").getResultList();
|
||||
// Tests that Oracle does not run out of cursors.
|
||||
for ( int i = 0; i < 1000; i++ ) {
|
||||
try {
|
||||
entityManager.createNativeQuery( "Select 1 from NotExistedTable" ).getResultList();
|
||||
fail( "expected PersistenceException" );
|
||||
} catch (PersistenceException e) {
|
||||
}
|
||||
catch (PersistenceException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}finally {
|
||||
entityManager.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -67,10 +67,10 @@ public void testGenerateSchemaDoesNotProduceTheSameStatementTwice() throws Excep
|
||||
);
|
||||
|
||||
final String dropFileContent = new String( Files.readAllBytes( dropSchema.toPath() ) ).toLowerCase();
|
||||
assertThat( dropFileContent.contains( "drop table test_entity" ), is( true ) );
|
||||
assertThat( dropFileContent.contains( "drop table " ), is( true ) );
|
||||
assertThat(
|
||||
"The statement 'drop table test_entity' is generated twice",
|
||||
dropFileContent.replaceFirst( "drop table test_entity", "" ).contains( "drop table test_entity" ),
|
||||
"The statement 'drop table ' is generated twice",
|
||||
dropFileContent.replaceFirst( "drop table ", "" ).contains( "drop table " ),
|
||||
is( false )
|
||||
);
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
import org.hibernate.tool.schema.TargetType;
|
||||
import org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl;
|
||||
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToStdout;
|
||||
import org.hibernate.tool.schema.spi.ExceptionHandler;
|
||||
import org.hibernate.tool.schema.spi.ExecutionOptions;
|
||||
import org.hibernate.tool.schema.spi.SchemaManagementTool;
|
||||
@ -118,15 +117,24 @@ public ScriptTargetOutput getScriptTargetOutput() {
|
||||
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||
}
|
||||
|
||||
class TargetImpl extends ScriptTargetOutputToStdout {
|
||||
class TargetImpl implements ScriptTargetOutput {
|
||||
boolean found = false;
|
||||
|
||||
@Override
|
||||
public void prepare() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String action) {
|
||||
super.accept( action );
|
||||
if ( action.startsWith( "insert into test_seq" ) ) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
package org.hibernate.test.sql.hand.query;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
@ -142,7 +143,7 @@ public void testFailOnNoAddEntityOrScalar() {
|
||||
s.createSQLQuery( sql ).list();
|
||||
fail( "Should throw an exception since no addEntity nor addScalar has been performed." );
|
||||
}
|
||||
catch( HibernateException he) {
|
||||
catch( PersistenceException pe) {
|
||||
// expected behavior
|
||||
}
|
||||
finally {
|
||||
|
@ -18,7 +18,9 @@
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Chris Cranford
|
||||
@ -115,7 +117,8 @@ public void testCompany1EmployeeIn() {
|
||||
assertEquals( 2, results.size() );
|
||||
final Employee employee1 = makeEmployee( employee1Id, "Employee1", company1Id, "COMPANY1" );
|
||||
final Employee employee2 = makeEmployee( employee2Id, "Employee2", company1Id, "COMPANY1" );
|
||||
assertEquals( results, TestTools.makeList( employee1, employee2 ) );
|
||||
assertThat( results.contains( employee1 ), is(true) );
|
||||
assertThat( results.contains( employee2 ), is(true) );
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -124,9 +127,11 @@ public void testCompany2EmployeeIn() {
|
||||
auditQuery.add( AuditEntity.relatedId( "company" ).in( new Integer[]{ company2Id } ) );
|
||||
final List<Employee> results = auditQuery.getResultList();
|
||||
assertEquals( 2, results.size() );
|
||||
|
||||
final Employee employee1 = makeEmployee( employee2Id, "Employee2", company2Id, "COMPANY2" );
|
||||
final Employee employee2 = makeEmployee( employee3Id, "Employee3", company2Id, "COMPANY2" );
|
||||
assertEquals( results, TestTools.makeList( employee1, employee2 ) );
|
||||
assertThat( results.contains( employee1 ), is(true) );
|
||||
assertThat( results.contains( employee2 ), is(true) );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user