Merge branch 'master' of github.com:hibernate/hibernate-core

This commit is contained in:
Gail Badner 2011-03-04 11:33:28 -08:00
commit 537ee25e82
18 changed files with 143 additions and 135 deletions

View File

@ -53,7 +53,7 @@ public void injectUploadTask(Upload uploadTask) {
@TaskAction @TaskAction
public void configureUploadAuthentication() { public void configureUploadAuthentication() {
// todo : unfortunately I have no idea how to apply this to non MavenDeployer-type repos... // todo : unfortunately I have no idea how to apply this to non MavenDeployer-type repos...
uploadTask.getRepositories().withType( MavenDeployer.class ).allObjects( uploadTask.getRepositories().withType( MavenDeployer.class ).all(
new Action<MavenDeployer>() { new Action<MavenDeployer>() {
public void execute(MavenDeployer deployer) { public void execute(MavenDeployer deployer) {
final RemoteRepository repository = deployer.getRepository(); final RemoteRepository repository = deployer.getRepository();

View File

@ -43,7 +43,7 @@ public void apply(final Project project) {
// code for just that. // code for just that.
final AuthenticationProviderRegistry registry = new AuthenticationProviderRegistry(); final AuthenticationProviderRegistry registry = new AuthenticationProviderRegistry();
project.getTasks().withType( Upload.class ).allTasks( project.getTasks().withType( Upload.class ).all(
new Action<Upload>() { new Action<Upload>() {
@Override @Override
public void execute(final Upload uploadTask) { public void execute(final Upload uploadTask) {

View File

@ -920,39 +920,25 @@ public interface Session extends Serializable {
public void doWork(Work work) throws HibernateException; public void doWork(Work work) throws HibernateException;
/** /**
* Disconnect the <tt>Session</tt> from the current JDBC connection. If * Disconnect the session from its underlying JDBC connection. This is intended for use in cases where the
* the connection was obtained by Hibernate close it and return it to * application has supplied the JDBC connection to the session and which require long-sessions (aka, conversations).
* the connection pool; otherwise, return it to the application.
* <p/> * <p/>
* This is used by applications which supply JDBC connections to Hibernate * It is considered an error to call this method on a session which was not opened by supplying the JDBC connection
* and which require long-sessions (or long-conversations) * and an exception will be thrown.
* <p/> * <p/>
* Note that disconnect() called on a session where the connection was * For non-user-supplied scenarios, normal transaction management already handles disconnection and reconnection
* retrieved by Hibernate through its configured * automatically.
* {@link org.hibernate.service.jdbc.connections.spi.ConnectionProvider} has no effect,
* provided {@link ConnectionReleaseMode#ON_CLOSE} is not in effect.
* *
* @return the application-supplied connection or <tt>null</tt> * @return the application-supplied connection or {@literal null}
*
* @see SessionFactory#openSession(java.sql.Connection)
* @see SessionFactory#openSession(java.sql.Connection, Interceptor)
* @see #reconnect(Connection) * @see #reconnect(Connection)
* @see #reconnect()
*/ */
Connection disconnect() throws HibernateException; Connection disconnect() throws HibernateException;
/** /**
* Obtain a new JDBC connection. This is used by applications which * Reconnect to the given JDBC connection.
* require long transactions and do not supply connections to the
* session.
*
* @see #disconnect()
* @deprecated Manual reconnection is only needed in the case of
* application-supplied connections, in which case the
* {@link #reconnect(java.sql.Connection)} for should be used.
*/
void reconnect() throws HibernateException;
/**
* Reconnect to the given JDBC connection. This is used by applications
* which require long transactions and use application-supplied connections.
* *
* @param connection a JDBC connection * @param connection a JDBC connection
* @see #disconnect() * @see #disconnect()

View File

@ -331,6 +331,15 @@ private void releaseConnection() throws JDBCException {
releaseNonDurableObservers(); releaseNonDurableObservers();
} }
private void releaseNonDurableObservers() {
Iterator observers = this.observers.iterator();
while ( observers.hasNext() ) {
if ( NonDurableConnectionObserver.class.isInstance( observers.next() ) ) {
observers.remove();
}
}
}
@Override @Override
public Connection manualDisconnect() { public Connection manualDisconnect() {
if ( isClosed ) { if ( isClosed ) {
@ -343,26 +352,20 @@ public Connection manualDisconnect() {
return c; return c;
} }
private void releaseNonDurableObservers() {
Iterator observers = this.observers.iterator();
while ( observers.hasNext() ) {
if ( NonDurableConnectionObserver.class.isInstance( observers.next() ) ) {
observers.remove();
}
}
}
@Override @Override
public void manualReconnect(Connection suppliedConnection) { public void manualReconnect(Connection suppliedConnection) {
if ( isClosed ) { if ( isClosed ) {
throw new IllegalStateException( "cannot manually reconnect because logical connection is already closed" ); throw new IllegalStateException( "cannot manually reconnect because logical connection is already closed" );
} }
if ( isUserSuppliedConnection ) { if ( !isUserSuppliedConnection ) {
throw new IllegalStateException( "cannot manually reconnect unless Connection was originally supplied" );
}
else {
if ( suppliedConnection == null ) { if ( suppliedConnection == null ) {
throw new IllegalArgumentException( "cannot reconnect a null user-supplied connection" ); throw new IllegalArgumentException( "cannot reconnect a null user-supplied connection" );
} }
else if ( suppliedConnection == physicalConnection ) { else if ( suppliedConnection == physicalConnection ) {
log.warn( "reconnecting the same connection that is already connected; should this connection have been disconnected?" ); log.debug( "reconnecting the same connection that is already connected; should this connection have been disconnected?" );
} }
else if ( physicalConnection != null ) { else if ( physicalConnection != null ) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -372,12 +375,6 @@ else if ( physicalConnection != null ) {
physicalConnection = suppliedConnection; physicalConnection = suppliedConnection;
log.debug( "reconnected JDBC connection" ); log.debug( "reconnected JDBC connection" );
} }
else {
if ( suppliedConnection != null ) {
throw new IllegalStateException( "unexpected user-supplied connection" );
}
log.debug( "called reconnect() with null connection (not user-supplied)" );
}
} }
@Override @Override

View File

@ -41,6 +41,7 @@
import org.hibernate.engine.transaction.spi.TransactionContext; import org.hibernate.engine.transaction.spi.TransactionContext;
import org.hibernate.engine.transaction.spi.TransactionEnvironment; import org.hibernate.engine.transaction.spi.TransactionEnvironment;
import java.io.Serializable;
import java.util.List; import java.util.List;
/** /**
@ -48,7 +49,7 @@
* *
* @author Gavin King * @author Gavin King
*/ */
public abstract class AbstractSessionImpl implements SessionImplementor, TransactionContext { public abstract class AbstractSessionImpl implements Serializable, SessionImplementor, TransactionContext {
protected transient SessionFactoryImpl factory; protected transient SessionFactoryImpl factory;
private boolean closed = false; private boolean closed = false;

View File

@ -544,19 +544,14 @@ public boolean isTransactionInProgress() {
return !isClosed() && transactionCoordinator.isTransactionInProgress(); return !isClosed() && transactionCoordinator.isTransactionInProgress();
} }
@Override
public Connection disconnect() throws HibernateException { public Connection disconnect() throws HibernateException {
errorIfClosed(); errorIfClosed();
log.debug( "disconnecting session" ); log.debug( "disconnecting session" );
return transactionCoordinator.getJdbcCoordinator().getLogicalConnection().manualDisconnect(); return transactionCoordinator.getJdbcCoordinator().getLogicalConnection().manualDisconnect();
} }
public void reconnect() throws HibernateException { @Override
errorIfClosed();
log.debug( "reconnecting session" );
checkTransactionSynchStatus();
transactionCoordinator.getJdbcCoordinator().getLogicalConnection().manualReconnect( null );
}
public void reconnect(Connection conn) throws HibernateException { public void reconnect(Connection conn) throws HibernateException {
errorIfClosed(); errorIfClosed();
log.debug( "reconnecting session" ); log.debug( "reconnecting session" );

View File

@ -269,6 +269,26 @@ public void testManyToOneNonPk() throws Exception {
s.close(); s.close();
} }
public void testManyToOneNonPkSecondaryTable() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Order order = new Order();
order.setOrderNbr( "123" );
s.persist( order );
OrderLine ol = new OrderLine();
ol.setItem( "Mouse" );
ol.setReplacementOrder( order );
s.persist( ol );
s.flush();
s.clear();
ol = (OrderLine) s.get( OrderLine.class, ol.getId() );
assertNotNull( ol.getReplacementOrder() );
assertEquals( "123", ol.getReplacementOrder().getOrderNbr() );
assertFalse( ol.getReplacementOrder().getOrderLines().contains( ol ) );
tx.rollback();
s.close();
}
public void testTwoManyToOneNonPk() throws Exception { public void testTwoManyToOneNonPk() throws Exception {
//2 many to one non pk pointing to the same referencedColumnName should not fail //2 many to one non pk pointing to the same referencedColumnName should not fail
Session s = openSession(); Session s = openSession();

View File

@ -6,15 +6,18 @@
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.SecondaryTable;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Entity @Entity
@SecondaryTable(name="OrderLine_Extension")
public class OrderLine { public class OrderLine {
private Integer id; private Integer id;
private String item; private String item;
private Order order; private Order order;
private Order replacementOrder;
@Id @GeneratedValue @Id @GeneratedValue
public Integer getId() { public Integer getId() {
@ -42,4 +45,14 @@ public Order getOrder() {
public void setOrder(Order order) { public void setOrder(Order order) {
this.order = order; this.order = order;
} }
@ManyToOne
@JoinColumn(name="replacement_order_nbr", table="OrderLine_Extension", referencedColumnName = "order_nbr")
public Order getReplacementOrder() {
return replacementOrder;
}
public void setReplacementOrder(Order replacementOrder) {
this.replacementOrder = replacementOrder;
}
} }

View File

@ -7,16 +7,19 @@
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.SecondaryTable;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Entity @Entity
@SecondaryTable(name="CLIENT_EXTENSION")
public class Client { public class Client {
private Integer id; private Integer id;
private String name; private String name;
private Address address; private Address address;
private Address secondaryAddress;
@OneToOne(cascade = CascadeType.ALL) @OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "ADDRESS_ID") @JoinColumn(name = "ADDRESS_ID")
@ -28,6 +31,16 @@ public void setAddress(Address address) {
this.address = address; this.address = address;
} }
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "SECONDARY_ADDRESS_ID", table="CLIENT_EXTENSION")
public Address getSecondaryAddress() {
return secondaryAddress;
}
public void setSecondaryAddress(Address secondaryAddress) {
this.secondaryAddress = secondaryAddress;
}
@Id @Id
@GeneratedValue @GeneratedValue
public Integer getId() { public Integer getId() {

View File

@ -108,6 +108,31 @@ public void testOneToOneWithExplicitFk() throws Exception {
s.close(); s.close();
} }
public void testOneToOneWithExplicitSecondaryTableFk() throws Exception {
Client c = new Client();
Address a = new Address();
a.setCity( "Paris" );
c.setName( "Emmanuel" );
c.setSecondaryAddress( a );
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
s.persist( c );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
c = ( Client ) s.get( Client.class, c.getId() );
assertNotNull( c );
assertNotNull( c.getSecondaryAddress() );
assertEquals( "Paris", c.getSecondaryAddress().getCity() );
tx.commit();
s.close();
}
public void testUnidirectionalTrueOneToOne() throws Exception { public void testUnidirectionalTrueOneToOne() throws Exception {
Body b = new Body(); Body b = new Body();
Heart h = new Heart(); Heart h = new Heart();

View File

@ -53,8 +53,8 @@ protected Session getSessionUnderTest() throws Throwable {
return openSession(); return openSession();
} }
@Override
protected void reconnect(Session session) { protected void reconnect(Session session) {
session.reconnect();
} }
protected void prepare() throws Throwable { protected void prepare() throws Throwable {

View File

@ -29,7 +29,6 @@ protected Session getSessionUnderTest() {
} }
protected void reconnect(Session session) { protected void reconnect(Session session) {
session.reconnect();
} }
public void configure(Configuration cfg) { public void configure(Configuration cfg) {

View File

@ -75,6 +75,10 @@ protected void release(Session session) {
} }
} }
protected void disconnect(Session session) throws Throwable {
session.disconnect();
}
/** /**
* Perform any steps needed to reconnect a fixture session. * Perform any steps needed to reconnect a fixture session.
* *
@ -139,7 +143,7 @@ public final void testEnabledFilterSerialization() throws Throwable {
sessionUnderTest.enableFilter( "nameIsNull" ); sessionUnderTest.enableFilter( "nameIsNull" );
assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) ); assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) );
sessionUnderTest.disconnect(); disconnect( sessionUnderTest );
assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) ); assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) );
byte[] bytes = SerializationHelper.serialize( sessionUnderTest ); byte[] bytes = SerializationHelper.serialize( sessionUnderTest );
@ -147,7 +151,7 @@ public final void testEnabledFilterSerialization() throws Throwable {
assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) ); assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) );
reconnect( sessionUnderTest ); reconnect( sessionUnderTest );
assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) ); assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) );
sessionUnderTest.disconnect(); disconnect( sessionUnderTest );
assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) ); assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) );
Session s2 = ( Session ) SerializationHelper.deserialize( bytes ); Session s2 = ( Session ) SerializationHelper.deserialize( bytes );
@ -156,7 +160,7 @@ public final void testEnabledFilterSerialization() throws Throwable {
reconnect( s2 ); reconnect( s2 );
assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) ); assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) );
s2.disconnect(); disconnect( s2 );
assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) ); assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) );
reconnect( s2 ); reconnect( s2 );
assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) ); assertNotNull( sessionUnderTest.getEnabledFilter( "nameIsNull" ) );
@ -174,7 +178,7 @@ public final void testManualDisconnectedSerialization() throws Throwable {
prepare(); prepare();
Session sessionUnderTest = getSessionUnderTest(); Session sessionUnderTest = getSessionUnderTest();
sessionUnderTest.disconnect(); disconnect( sessionUnderTest );
SerializationHelper.serialize( sessionUnderTest ); SerializationHelper.serialize( sessionUnderTest );
checkSerializedState( sessionUnderTest ); checkSerializedState( sessionUnderTest );
@ -191,7 +195,7 @@ public final void testManualDisconnectChain() throws Throwable {
prepare(); prepare();
Session sessionUnderTest = getSessionUnderTest(); Session sessionUnderTest = getSessionUnderTest();
sessionUnderTest.disconnect(); disconnect( sessionUnderTest );
byte[] bytes = SerializationHelper.serialize( sessionUnderTest ); byte[] bytes = SerializationHelper.serialize( sessionUnderTest );
checkSerializedState( sessionUnderTest ); checkSerializedState( sessionUnderTest );
@ -200,7 +204,7 @@ public final void testManualDisconnectChain() throws Throwable {
reconnect( s2 ); reconnect( s2 );
s2.disconnect(); disconnect( s2 );
reconnect( s2 ); reconnect( s2 );
release( sessionUnderTest ); release( sessionUnderTest );
@ -224,14 +228,14 @@ public final void testManualDisconnectWithOpenResources() throws Throwable {
sessionUnderTest.createQuery( "from Silly" ).iterate(); sessionUnderTest.createQuery( "from Silly" ).iterate();
sessionUnderTest.disconnect(); disconnect( sessionUnderTest );
SerializationHelper.serialize( sessionUnderTest ); SerializationHelper.serialize( sessionUnderTest );
checkSerializedState( sessionUnderTest ); checkSerializedState( sessionUnderTest );
reconnect( sessionUnderTest ); reconnect( sessionUnderTest );
sessionUnderTest.createQuery( "from Silly" ).scroll(); sessionUnderTest.createQuery( "from Silly" ).scroll();
sessionUnderTest.disconnect(); disconnect( sessionUnderTest );
SerializationHelper.serialize( sessionUnderTest ); SerializationHelper.serialize( sessionUnderTest );
checkSerializedState( sessionUnderTest ); checkSerializedState( sessionUnderTest );

View File

@ -8,6 +8,7 @@
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.context.ThreadLocalSessionContext; import org.hibernate.context.ThreadLocalSessionContext;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.transaction.spi.LocalStatus;
import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite; import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
/** /**
@ -36,6 +37,10 @@ protected Session getSessionUnderTest() throws Throwable {
} }
protected void release(Session session) { protected void release(Session session) {
if ( session.getTransaction().getLocalStatus() != LocalStatus.ACTIVE ) {
TestableThreadLocalContext.unbind( sfi() );
return;
}
long initialCount = getSessions().getStatistics().getSessionCloseCount(); long initialCount = getSessions().getStatistics().getSessionCloseCount();
session.getTransaction().commit(); session.getTransaction().commit();
long subsequentCount = getSessions().getStatistics().getSessionCloseCount(); long subsequentCount = getSessions().getStatistics().getSessionCloseCount();
@ -45,8 +50,6 @@ protected void release(Session session) {
} }
protected void reconnect(Session session) throws Throwable { protected void reconnect(Session session) throws Throwable {
// session.reconnect();
session.beginTransaction();
} }
protected void checkSerializedState(Session session) { protected void checkSerializedState(Session session) {

View File

@ -1358,9 +1358,7 @@ public void testQueryLockMode() throws Exception {
Object b = result[0]; Object b = result[0];
assertTrue( s.getCurrentLockMode(b)==LockMode.WRITE && s.getCurrentLockMode( result[1] )==LockMode.WRITE ); assertTrue( s.getCurrentLockMode(b)==LockMode.WRITE && s.getCurrentLockMode( result[1] )==LockMode.WRITE );
tx.commit(); tx.commit();
s.disconnect();
s.reconnect();
tx = s.beginTransaction(); tx = s.beginTransaction();
assertTrue( s.getCurrentLockMode(b)==LockMode.NONE ); assertTrue( s.getCurrentLockMode(b)==LockMode.NONE );
s.createQuery( "from Foo foo" ).list(); s.createQuery( "from Foo foo" ).list();
@ -1371,9 +1369,7 @@ public void testQueryLockMode() throws Exception {
assertTrue( s.getCurrentLockMode(b)==LockMode.READ); assertTrue( s.getCurrentLockMode(b)==LockMode.READ);
s.evict(baz); s.evict(baz);
tx.commit(); tx.commit();
s.disconnect();
s.reconnect();
tx = s.beginTransaction(); tx = s.beginTransaction();
assertTrue( s.getCurrentLockMode(b)==LockMode.NONE ); assertTrue( s.getCurrentLockMode(b)==LockMode.NONE );
s.delete( s.load( Baz.class, baz.getCode() ) ); s.delete( s.load( Baz.class, baz.getCode() ) );
@ -2575,12 +2571,9 @@ public void testPersistCollections() throws Exception {
assertTrue( baz.getCascadingBars().size()==1 ); assertTrue( baz.getCascadingBars().size()==1 );
txn.commit(); txn.commit();
s.disconnect();
s2 = (Session) SerializationHelper.deserialize( SerializationHelper.serialize(s) ); s2 = (Session) SerializationHelper.deserialize( SerializationHelper.serialize(s) );
s.close(); s.close();
s2.reconnect();
txn2 = s2.beginTransaction(); txn2 = s2.beginTransaction();
baz = (Baz) s2.load(Baz.class, baz.getCode()); baz = (Baz) s2.load(Baz.class, baz.getCode());
assertTrue( ( (Long) s2.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue()==3 ); assertTrue( ( (Long) s2.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue()==3 );
@ -3951,35 +3944,6 @@ public void testNewSessionLifecycle() throws Exception {
} }
} }
public void testDisconnect() throws Exception {
Session s = openSession();
s.beginTransaction();
Foo foo = new Foo();
Foo foo2 = new Foo();
s.save(foo);
s.save(foo2);
foo2.setFoo(foo);
s.getTransaction().commit();
s.disconnect();
s.reconnect();
s.beginTransaction();
s.delete(foo);
foo2.setFoo(null);
s.getTransaction().commit();
s.disconnect();
s.reconnect();
s.beginTransaction();
s.delete(foo2);
s.getTransaction().commit();
s.close();
}
public void testOrderBy() throws Exception { public void testOrderBy() throws Exception {
Session s = openSession(); Session s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -4838,9 +4802,7 @@ public void testWierdSession() throws Exception {
t = s.beginTransaction(); t = s.beginTransaction();
Foo foo = (Foo) s.get(Foo.class, id); Foo foo = (Foo) s.get(Foo.class, id);
t.commit(); t.commit();
s.disconnect();
s.reconnect();
t = s.beginTransaction(); t = s.beginTransaction();
s.flush(); s.flush();
t.commit(); t.commit();

View File

@ -735,6 +735,7 @@ public void testUnflushedSessionSerialization() throws Exception {
// Test insertions across serializations // Test insertions across serializations
Session s = getSessions().openSession(); Session s = getSessions().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple();
simple.setAddress("123 Main St. Anytown USA"); simple.setAddress("123 Main St. Anytown USA");
@ -745,11 +746,11 @@ public void testUnflushedSessionSerialization() throws Exception {
s.save( simple, new Long(10) ); s.save( simple, new Long(10) );
// Now, try to serialize session without flushing... // Now, try to serialize session without flushing...
s.disconnect(); s.getTransaction().commit();
Session s2 = spoofSerialization(s); Session s2 = spoofSerialization(s);
s.close(); s.close();
s = s2; s = s2;
s.reconnect(); s.beginTransaction();
simple = (Simple) s.load( Simple.class, new Long(10) ); simple = (Simple) s.load( Simple.class, new Long(10) );
Simple other = new Simple(); Simple other = new Simple();
@ -759,7 +760,7 @@ public void testUnflushedSessionSerialization() throws Exception {
simple.setOther(other); simple.setOther(other);
s.flush(); s.flush();
s.connection().commit(); s.getTransaction().commit();
s.close(); s.close();
Simple check = simple; Simple check = simple;
@ -767,6 +768,7 @@ public void testUnflushedSessionSerialization() throws Exception {
// Test updates across serializations // Test updates across serializations
s = getSessions().openSession(); s = getSessions().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction();
simple = (Simple) s.get( Simple.class, new Long(10) ); simple = (Simple) s.get( Simple.class, new Long(10) );
assertTrue("Not same parent instances", check.getName().equals( simple.getName() ) ); assertTrue("Not same parent instances", check.getName().equals( simple.getName() ) );
@ -774,14 +776,14 @@ public void testUnflushedSessionSerialization() throws Exception {
simple.setName("My updated name"); simple.setName("My updated name");
s.disconnect(); s.getTransaction().commit();
s2 = spoofSerialization(s); s2 = spoofSerialization(s);
s.close(); s.close();
s = s2; s = s2;
s.reconnect(); s.beginTransaction();
s.flush(); s.flush();
s.connection().commit(); s.getTransaction().commit();
s.close(); s.close();
check = simple; check = simple;
@ -789,6 +791,7 @@ public void testUnflushedSessionSerialization() throws Exception {
// Test deletions across serializations // Test deletions across serializations
s = getSessions().openSession(); s = getSessions().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction();
simple = (Simple) s.get( Simple.class, new Long(10) ); simple = (Simple) s.get( Simple.class, new Long(10) );
assertTrue("Not same parent instances", check.getName().equals( simple.getName() ) ); assertTrue("Not same parent instances", check.getName().equals( simple.getName() ) );
@ -797,20 +800,21 @@ public void testUnflushedSessionSerialization() throws Exception {
// Now, lets delete across serialization... // Now, lets delete across serialization...
s.delete(simple); s.delete(simple);
s.disconnect(); s.getTransaction().commit();
s2 = spoofSerialization(s); s2 = spoofSerialization(s);
s.close(); s.close();
s = s2; s = s2;
s.reconnect(); s.beginTransaction();
s.flush(); s.flush();
s.connection().commit(); s.getTransaction().commit();
s.close(); s.close();
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Test collection actions across serializations // Test collection actions across serializations
s = getSessions().openSession(); s = getSessions().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction();
Fum fum = new Fum( fumKey("uss-fum") ); Fum fum = new Fum( fumKey("uss-fum") );
fum.setFo( new Fum( fumKey("uss-fo") ) ); fum.setFo( new Fum( fumKey("uss-fo") ) );
@ -828,32 +832,33 @@ public void testUnflushedSessionSerialization() throws Exception {
s.save( fum.getFo() ); s.save( fum.getFo() );
s.save(fum); s.save(fum);
s.disconnect(); s.getTransaction().commit();
s2 = spoofSerialization(s); s2 = spoofSerialization(s);
s.close(); s.close();
s = s2; s = s2;
s.reconnect(); s.beginTransaction();
s.flush(); s.flush();
s.connection().commit(); s.getTransaction().commit();
s.close(); s.close();
s = getSessions().openSession(); s = getSessions().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction();
fum = (Fum) s.load( Fum.class, fum.getId() ); fum = (Fum) s.load( Fum.class, fum.getId() );
assertTrue("the Fum.friends did not get saved", fum.getFriends().size() == 2); assertTrue("the Fum.friends did not get saved", fum.getFriends().size() == 2);
fum.setFriends(null); fum.setFriends(null);
s.disconnect(); s.getTransaction().commit();
s2 = spoofSerialization(s); s2 = spoofSerialization(s);
s.close(); s.close();
s = s2; s = s2;
s.reconnect(); s.beginTransaction();
s.flush(); s.flush();
s.connection().commit(); s.getTransaction().commit();
s.close(); s.close();
s = getSessions().openSession(); s = getSessions().openSession();

View File

@ -181,7 +181,6 @@ public void testProxySerialization() {
//close the original: //close the original:
s.close(); s.close();
sclone.reconnect();
t = sclone.beginTransaction(); t = sclone.beginTransaction();
DataPoint sdp = (DataPoint) sclone.load( DataPoint.class, new Long( dp.getId() ) ); DataPoint sdp = (DataPoint) sclone.load( DataPoint.class, new Long( dp.getId() ) );

View File

@ -11,6 +11,7 @@
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory; import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator; import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.service.jta.platform.spi.JtaPlatform; import org.hibernate.service.jta.platform.spi.JtaPlatform;
import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider; import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider;
@ -20,6 +21,7 @@
import org.hibernate.util.SerializationHelper; import org.hibernate.util.SerializationHelper;
import javax.transaction.Transaction; import javax.transaction.Transaction;
import java.sql.Connection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -469,22 +471,6 @@ public void testCurrentSessionWithScroll() throws Exception {
sfi().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit(); sfi().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
} }
public void testAggressiveReleaseWithExplicitDisconnectReconnect() throws Exception {
sfi().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
Session s = getSessions().getCurrentSession();
s.createQuery( "from Item" ).list();
s.disconnect();
byte[] bytes = SerializationHelper.serialize( s );
s = ( Session ) SerializationHelper.deserialize( bytes );
s.reconnect();
s.createQuery( "from Item" ).list();
sfi().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
}
public void testAggressiveReleaseWithConnectionRetreival() throws Exception { public void testAggressiveReleaseWithConnectionRetreival() throws Exception {
sfi().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin(); sfi().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
Session s = openSession(); Session s = openSession();