HHH-5207 : Unexpected exception occurs during refresh of a detached immutable entity
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19451 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
9d93984ca1
commit
14bdaec5e7
|
@ -152,7 +152,13 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
// Keep the same read-only/modifiable setting for the entity that it had before refreshing;
|
||||
// If it was transient, then set it to the default for the source.
|
||||
if ( result != null ) {
|
||||
source.setReadOnly( result, ( e == null ? source.isDefaultReadOnly() : e.isReadOnly() ) );
|
||||
if ( ! persister.isMutable() ) {
|
||||
// this is probably redundant; it should already be read-only
|
||||
source.setReadOnly( result, true );
|
||||
}
|
||||
else {
|
||||
source.setReadOnly( result, ( e == null ? source.isDefaultReadOnly() : e.isReadOnly() ) );
|
||||
}
|
||||
}
|
||||
source.setFetchProfile(previousFetchProfile);
|
||||
|
||||
|
|
|
@ -361,6 +361,84 @@ public class ImmutableTest extends FunctionalTestCase {
|
|||
assertDeleteCount( 3 );
|
||||
}
|
||||
|
||||
public void testRefreshImmutable() {
|
||||
clearCounts();
|
||||
|
||||
Contract c = new Contract( null, "gavin", "phone");
|
||||
ContractVariation cv1 = new ContractVariation(1, c);
|
||||
cv1.setText("expensive");
|
||||
ContractVariation cv2 = new ContractVariation(2, c);
|
||||
cv2.setText("more expensive");
|
||||
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
s.saveOrUpdate( c );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
assertInsertCount( 3 );
|
||||
assertUpdateCount( 0 );
|
||||
clearCounts();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
// refresh detached
|
||||
s.refresh( c );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
assertInsertCount( 0 );
|
||||
assertUpdateCount( 0 );
|
||||
clearCounts();
|
||||
|
||||
c.setCustomerName( "joe" );
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
// refresh updated detached
|
||||
s.refresh( c );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
it = c.getVariations().iterator();
|
||||
cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
assertInsertCount( 0 );
|
||||
assertUpdateCount( 0 );
|
||||
clearCounts();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
s.delete(c);
|
||||
assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
|
||||
assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertDeleteCount( 3 );
|
||||
}
|
||||
|
||||
public void testImmutable() {
|
||||
clearCounts();
|
||||
|
||||
|
|
Loading…
Reference in New Issue