mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 08:35:13 +00:00
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,8 +152,14 @@ public void onRefresh(RefreshEvent event, Map refreshedAlready) {
|
|||||||
// Keep the same read-only/modifiable setting for the entity that it had before refreshing;
|
// 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 it was transient, then set it to the default for the source.
|
||||||
if ( result != null ) {
|
if ( result != null ) {
|
||||||
|
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.setReadOnly( result, ( e == null ? source.isDefaultReadOnly() : e.isReadOnly() ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
source.setFetchProfile(previousFetchProfile);
|
source.setFetchProfile(previousFetchProfile);
|
||||||
|
|
||||||
UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
|
UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
|
||||||
|
@ -361,6 +361,84 @@ public void testSaveOrUpdateImmutable() {
|
|||||||
assertDeleteCount( 3 );
|
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() {
|
public void testImmutable() {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user