Re-enabled additional tests
This commit is contained in:
parent
3022371d3e
commit
a648e637cc
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.inheritance.discriminator;
|
||||
package org.hibernate.orm.test.inheritance.discriminator;
|
||||
|
||||
import java.sql.Statement;
|
||||
import java.util.Map;
|
||||
|
@ -17,27 +17,37 @@ import javax.persistence.Inheritance;
|
|||
import javax.persistence.InheritanceType;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-12445")
|
||||
public class SingleTableNullNotNullDiscriminatorTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
SingleTableNullNotNullDiscriminatorTest.RootEntity.class,
|
||||
SingleTableNullNotNullDiscriminatorTest.Val1Entity.class,
|
||||
SingleTableNullNotNullDiscriminatorTest.Val2Entity.class,
|
||||
SingleTableNullNotNullDiscriminatorTest.NotNullEntity.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class SingleTableNullNotNullDiscriminatorTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
RootEntity.class,
|
||||
Val1Entity.class,
|
||||
Val2Entity.class,
|
||||
NotNullEntity.class
|
||||
};
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from root_ent" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
inTransaction( session -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
Val1Entity val1 = new Val1Entity();
|
||||
val1.setId( 1L );
|
||||
|
||||
|
@ -61,7 +71,7 @@ public class SingleTableNullNotNullDiscriminatorTest extends BaseCoreFunctionalT
|
|||
} );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
Map<Long, RootEntity> entities = session.createQuery(
|
||||
"select e from root_ent e", RootEntity.class )
|
||||
.getResultList()
|
||||
|
@ -83,6 +93,8 @@ public class SingleTableNullNotNullDiscriminatorTest extends BaseCoreFunctionalT
|
|||
@Id
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.reattachment;
|
||||
package org.hibernate.orm.test.reattachment;
|
||||
|
||||
|
||||
/**
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.reattachment;
|
||||
package org.hibernate.orm.test.reattachment;
|
||||
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
|
@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = " org/hibernate/test/reattachment/Mappings.hbm.xml"
|
||||
xmlMappings = "org/hibernate/orm/test/reattachment/Mappings.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class CollectionReattachmentTest {
|
|
@ -10,7 +10,7 @@
|
|||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.reattachment">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.reattachment">
|
||||
|
||||
<class name="Parent">
|
||||
<id name="name" column="NAME" type="string" />
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.reattachment;
|
||||
package org.hibernate.orm.test.reattachment;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.orm.test.reattachment;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test of proxy reattachment semantics
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/reattachment/Mappings.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class ProxyReattachmentTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Parent" ).executeUpdate();
|
||||
session.createQuery( "delete from Child" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAfterEvict(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent p = new Parent( "p" );
|
||||
session.save( p );
|
||||
}
|
||||
);
|
||||
|
||||
Parent parent = scope.fromTransaction(
|
||||
session -> {
|
||||
Parent p = session.load( Parent.class, "p" );
|
||||
// evict...
|
||||
session.evict( p );
|
||||
// now try to reattach...
|
||||
session.update( p );
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( parent )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAfterClear(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent p = new Parent( "p" );
|
||||
session.save( p );
|
||||
}
|
||||
);
|
||||
|
||||
Parent parent = scope.fromTransaction(
|
||||
session -> {
|
||||
Parent p = session.load( Parent.class, "p" );
|
||||
// clear...
|
||||
session.clear();
|
||||
// now try to reattach...
|
||||
session.update( p );
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( parent )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8374")
|
||||
public void testRemoveAndReattachProxyEntity(SessionFactoryScope scope) {
|
||||
Parent p = new Parent( "foo" );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( p );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent parent = session.load( Parent.class, p.getName() );
|
||||
session.delete( parent );
|
||||
// re-attach
|
||||
session.persist( parent );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,270 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.reattachment;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test of proxy reattachment semantics
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/test/reattachment/Mappings.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class ProxyReattachmentTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Parent" );
|
||||
session.createQuery( "delete from Child" );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAfterEvict(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent p = new Parent( "p" );
|
||||
session.save( p );
|
||||
}
|
||||
);
|
||||
|
||||
Parent parent = scope.fromTransaction(
|
||||
session -> {
|
||||
Parent p = session.load( Parent.class, "p" );
|
||||
// evict...
|
||||
session.evict( p );
|
||||
// now try to reattach...
|
||||
session.update( p );
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( parent )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAfterClear(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent p = new Parent( "p" );
|
||||
session.save( p );
|
||||
}
|
||||
);
|
||||
|
||||
Parent parent = scope.fromTransaction(
|
||||
session -> {
|
||||
Parent p = session.load( Parent.class, "p" );
|
||||
// clear...
|
||||
session.clear();
|
||||
// now try to reattach...
|
||||
session.update( p );
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( parent )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testIterateWithClearTopOfLoop(SessionFactoryScope scope) {
|
||||
Set parents = new HashSet();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( int i = 0; i < 5; i++ ) {
|
||||
Parent p = new Parent( String.valueOf( i ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
session.save( p );
|
||||
parents.add( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
int i = 0;
|
||||
List<Parent> fromParent = session.createQuery( "from Parent" ).list();
|
||||
for ( Parent p : fromParent ) {
|
||||
i++;
|
||||
if ( i % 2 == 0 ) {
|
||||
session.flush();
|
||||
session.clear();
|
||||
}
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( Object parent : parents ) {
|
||||
session.delete( parent );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testIterateWithClearBottomOfLoop(SessionFactoryScope scope) {
|
||||
Set parents = new HashSet();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( int i = 0; i < 5; i++ ) {
|
||||
Parent p = new Parent( String.valueOf( i ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
session.save( p );
|
||||
parents.add( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
int i = 0;
|
||||
List<Parent> fromParent = session.createQuery( "from Parent" ).list();
|
||||
for ( Parent p : fromParent ) {
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
i++;
|
||||
if ( i % 2 == 0 ) {
|
||||
session.flush();
|
||||
session.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( Object parent : parents ) {
|
||||
session.delete( parent );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testIterateWithEvictTopOfLoop(SessionFactoryScope scope) {
|
||||
Set parents = new HashSet();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( int i = 0; i < 5; i++ ) {
|
||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
session.save( p );
|
||||
parents.add( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<Parent> fromParent = session.createQuery( "from Parent" ).list();
|
||||
for ( Parent p : fromParent ) {
|
||||
if ( p != null ) {
|
||||
session.evict( p );
|
||||
}
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( Object parent : parents ) {
|
||||
session.delete( parent );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testIterateWithEvictBottomOfLoop(SessionFactoryScope scope) {
|
||||
Set parents = new HashSet();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( int i = 0; i < 5; i++ ) {
|
||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
session.save( p );
|
||||
parents.add( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<Parent> fromParent = session.createQuery( "from Parent" ).list();
|
||||
for ( Parent p : fromParent ) {
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
session.evict( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( Object parent : parents ) {
|
||||
session.delete( parent );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8374")
|
||||
public void testRemoveAndReattachProxyEntity(SessionFactoryScope scope) {
|
||||
Parent p = new Parent( "foo" );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( p );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent parent = session.load( Parent.class, p.getName() );
|
||||
session.delete( parent );
|
||||
// re-attach
|
||||
session.persist( parent );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
|
|||
TestData testData=new TestData();
|
||||
testData.createData();
|
||||
StatelessSession s = sessionFactory().openStatelessSession();
|
||||
assertEquals( 1, s.createQuery( "from Contact c join fetch c.org join fetch c.org.country" )
|
||||
assertEquals( 1, s.createQuery( "from Contact c join fetch c.org o join fetch c.org.country" )
|
||||
.list().size() );
|
||||
s.close();
|
||||
testData.cleanData();
|
||||
|
@ -59,7 +59,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
|
|||
TestData testData=new TestData();
|
||||
testData.createData();
|
||||
|
||||
final String queryString = "from Contact c join fetch c.org join fetch c.org.country";
|
||||
final String queryString = "from Contact c join fetch c.org o join fetch o.country";
|
||||
StatelessSession s = sessionFactory().openStatelessSession();
|
||||
|
||||
org.hibernate.query.Query query = s.createQuery( queryString );
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
|
@ -54,7 +55,7 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
protected String applyPrefix(String baseTableName) {
|
||||
String prefixed = prefix + '_' + baseTableName;
|
||||
log.debug("prefixed table name : " + baseTableName + " -> " + prefixed);
|
||||
log.debug( "prefixed table name : " + baseTableName + " -> " + prefixed );
|
||||
return prefixed;
|
||||
}
|
||||
|
||||
|
@ -64,7 +65,7 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
private String determineUniquePrefix() {
|
||||
return StringHelper.collapseQualifier( getClass().getName(), false ).toUpperCase(Locale.ROOT);
|
||||
return StringHelper.collapseQualifier( getClass().getName(), false ).toUpperCase( Locale.ROOT );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,8 +87,8 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||
ss.beginTransaction();
|
||||
Task taskRef = ( Task ) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult();
|
||||
assertTrue( taskRef != null );
|
||||
Task taskRef = (Task) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult();
|
||||
assertNotNull( taskRef );
|
||||
assertTrue( Hibernate.isInitialized( taskRef ) );
|
||||
assertTrue( Hibernate.isInitialized( taskRef.getUser() ) );
|
||||
assertTrue( Hibernate.isInitialized( taskRef.getResource() ) );
|
||||
|
@ -130,10 +131,10 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
|||
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||
ss.beginTransaction();
|
||||
|
||||
final Query query = ss.createQuery( "from Task t join fetch t.resource join fetch t.user");
|
||||
final ScrollableResults scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY);
|
||||
final Query query = ss.createQuery( "from Task t join fetch t.resource join fetch t.user" );
|
||||
final ScrollableResults scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY );
|
||||
while ( scrollableResults.next() ) {
|
||||
Task taskRef = (Task) ( (Object[]) scrollableResults.get() )[0];
|
||||
Task taskRef = (Task) scrollableResults.get();
|
||||
assertTrue( Hibernate.isInitialized( taskRef ) );
|
||||
assertTrue( Hibernate.isInitialized( taskRef.getUser() ) );
|
||||
assertTrue( Hibernate.isInitialized( taskRef.getResource() ) );
|
||||
|
@ -177,10 +178,10 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
inTransaction(
|
||||
session -> {
|
||||
final Query query = session.createQuery( "from Task t join fetch t.resource join fetch t.user");
|
||||
final Query query = session.createQuery( "from Task t join fetch t.resource join fetch t.user" );
|
||||
final ScrollableResults scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY );
|
||||
while ( scrollableResults.next() ) {
|
||||
Task taskRef = (Task) ( (Object[]) scrollableResults.get() )[0];
|
||||
Task taskRef = (Task) scrollableResults.get();
|
||||
assertTrue( Hibernate.isInitialized( taskRef ) );
|
||||
assertTrue( Hibernate.isInitialized( taskRef.getUser() ) );
|
||||
assertTrue( Hibernate.isInitialized( taskRef.getResource() ) );
|
||||
|
@ -210,9 +211,9 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
|||
session.save( v1 );
|
||||
session.save( v2 );
|
||||
|
||||
final Product product1 = new Product(1, "123", v1, p1);
|
||||
final Product product2 = new Product(2, "456", v1, p1);
|
||||
final Product product3 = new Product(3, "789", v1, p2);
|
||||
final Product product1 = new Product( 1, "123", v1, p1 );
|
||||
final Product product2 = new Product( 2, "456", v1, p1 );
|
||||
final Product product3 = new Product( 3, "789", v1, p2 );
|
||||
|
||||
session.save( product1 );
|
||||
session.save( product2 );
|
||||
|
@ -225,24 +226,14 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
|||
ss.beginTransaction();
|
||||
|
||||
final Query query = ss.createQuery( "select p from Producer p join fetch p.products" );
|
||||
ScrollableResults scrollableResults = null;
|
||||
if ( getDialect() instanceof DB2Dialect ) {
|
||||
/*
|
||||
FetchingScrollableResultsImp#next() in order to check if the ResultSet is empty calls ResultSet#isBeforeFirst()
|
||||
but the support for ResultSet#isBeforeFirst() is optional for ResultSets with a result
|
||||
set type of TYPE_FORWARD_ONLY and db2 does not support it.
|
||||
*/
|
||||
scrollableResults = query.scroll( ScrollMode.SCROLL_INSENSITIVE );
|
||||
}
|
||||
else {
|
||||
scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY );
|
||||
}
|
||||
final ScrollableResults scrollableResults = getScrollableResults( query );
|
||||
|
||||
while ( scrollableResults.next() ) {
|
||||
Producer producer = (Producer) ( (Object[]) scrollableResults.get() )[0];
|
||||
Producer producer = (Producer) scrollableResults.get();
|
||||
assertTrue( Hibernate.isInitialized( producer ) );
|
||||
assertTrue( Hibernate.isInitialized( producer.getProducts() ) );
|
||||
|
||||
for (Product product : producer.getProducts()) {
|
||||
for ( Product product : producer.getProducts() ) {
|
||||
assertTrue( Hibernate.isInitialized( product ) );
|
||||
assertFalse( Hibernate.isInitialized( product.getVendor() ) );
|
||||
}
|
||||
|
@ -254,6 +245,21 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
|||
cleanup();
|
||||
}
|
||||
|
||||
private ScrollableResults getScrollableResults(Query query) {
|
||||
ScrollableResults scrollableResults;
|
||||
if ( getDialect() instanceof DB2Dialect ) {
|
||||
/*
|
||||
FetchingScrollableResultsImp#next() in order to check if the ResultSet is empty calls ResultSet#isBeforeFirst()
|
||||
but the support for ResultSet#isBeforeFirst() is optional for ResultSets with a result
|
||||
set type of TYPE_FORWARD_ONLY and db2 does not support it.
|
||||
*/
|
||||
return query.scroll( ScrollMode.SCROLL_INSENSITIVE );
|
||||
}
|
||||
else {
|
||||
return query.scroll( ScrollMode.FORWARD_ONLY );
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
|
|
|
@ -0,0 +1,191 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.reattachment;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test of proxy reattachment semantics
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ProxyReattachmentTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "reattachment/Mappings.hbm.xml" };
|
||||
}
|
||||
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testIterateWithClearTopOfLoop() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Set parents = new HashSet();
|
||||
for (int i=0; i<5; i++) {
|
||||
Parent p = new Parent( String.valueOf( i ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
s.save( p );
|
||||
parents.add(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
int i = 0;
|
||||
for ( Iterator it = session.createQuery( "from Parent p " ).iterate(); it.hasNext(); ) {
|
||||
i++;
|
||||
if (i % 2 == 0) {
|
||||
s.flush();
|
||||
s.clear();
|
||||
}
|
||||
Parent p = (Parent) it.next();
|
||||
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( Object parent : parents ) {
|
||||
s.delete( parent );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testIterateWithClearBottomOfLoop() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Set parents = new HashSet();
|
||||
for (int i=0; i<5; i++) {
|
||||
Parent p = new Parent( String.valueOf( i ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
s.save( p );
|
||||
parents.add(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
int i = 0;
|
||||
for (Iterator it = session.createQuery( "from Parent p " ).iterate(); it.hasNext(); ) {
|
||||
Parent p = (Parent) it.next();
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
i++;
|
||||
if (i % 2 == 0) {
|
||||
s.flush();
|
||||
s.clear();
|
||||
}
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( Object parent : parents ) {
|
||||
s.delete( parent );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testIterateWithEvictTopOfLoop() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Set parents = new HashSet();
|
||||
for (int i=0; i<5; i++) {
|
||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
s.save( p );
|
||||
parents.add(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
Parent p = null;
|
||||
for (Iterator it = session.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
|
||||
if ( p != null) { s.evict(p); }
|
||||
p = (Parent) it.next();
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( Object parent : parents ) {
|
||||
s.delete( parent );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testIterateWithEvictBottomOfLoop() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Set parents = new HashSet();
|
||||
for (int i=0; i<5; i++) {
|
||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
s.save( p );
|
||||
parents.add(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
|
||||
Parent p = (Parent) it.next();
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
s.evict(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( Object parent : parents ) {
|
||||
s.delete( parent );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue