HHH-8662 : Deprecate functionality for initialized many-to-many collections of proxies

This commit is contained in:
Gail Badner 2013-11-20 04:18:22 -08:00
parent f679a3c783
commit 412d5d6fca
3 changed files with 40 additions and 12 deletions

View File

@ -2095,21 +2095,41 @@ public final class HbmBinder {
}
}
else {
// use old (HB 2.1) defaults if outer-join is specified
String eoj = jfNode.getValue();
if ( "auto".equals( eoj ) ) {
fetchStyle = FetchMode.DEFAULT;
if ( "many-to-many".equals( node.getName() ) ) {
//NOTE <many-to-many outer-join="..." is deprecated.:
// Default to join and non-lazy for the "second join"
// of the many-to-many
LOG.deprecatedManyToManyOuterJoin();
lazy = false;
fetchStyle = FetchMode.JOIN;
}
else {
boolean join = "true".equals( eoj );
fetchStyle = join ? FetchMode.JOIN : FetchMode.SELECT;
// use old (HB 2.1) defaults if outer-join is specified
String eoj = jfNode.getValue();
if ( "auto".equals( eoj ) ) {
fetchStyle = FetchMode.DEFAULT;
}
else {
boolean join = "true".equals( eoj );
fetchStyle = join ? FetchMode.JOIN : FetchMode.SELECT;
}
}
}
}
else {
boolean join = "join".equals( fetchNode.getValue() );
//lazy = !join;
fetchStyle = join ? FetchMode.JOIN : FetchMode.SELECT;
if ( "many-to-many".equals( node.getName() ) ) {
//NOTE <many-to-many fetch="..." is deprecated.:
// Default to join and non-lazy for the "second join"
// of the many-to-many
LOG.deprecatedManyToManyFetch();
lazy = false;
fetchStyle = FetchMode.JOIN;
}
else {
boolean join = "join".equals( fetchNode.getValue() );
//lazy = !join;
fetchStyle = join ? FetchMode.JOIN : FetchMode.SELECT;
}
}
model.setFetchMode( fetchStyle );
model.setLazy(lazy);

View File

@ -1654,4 +1654,12 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Exception while discovering OSGi service implementations : %s", id = 453)
void unableToDiscoverOsgiService(String service, @Cause Exception e);
@LogMessage(level = WARN)
@Message(value = "The outer-join attribute on <many-to-many> has been deprecated. Instead of outer-join=\"false\", use lazy=\"extra\" with <map>, <set>, <bag>, <idbag>, or <list>, which will only initialize entities (not as a proxy) as needed.", id = 454)
void deprecatedManyToManyOuterJoin();
@LogMessage(level = WARN)
@Message(value = "The fetch attribute on <many-to-many> has been deprecated. Instead of fetch=\"select\", use lazy=\"extra\" with <map>, <set>, <bag>, <idbag>, or <list>, which will only initialize entities (not as a proxy) as needed.", id = 455)
void deprecatedManyToManyFetch();
}

View File

@ -4808,8 +4808,7 @@ public class FooBarTest extends LegacyTestCase {
s.close();
}
@Test
@FailureExpected( jiraKey = "HHH-8662")
@TestForIssue( jiraKey = "HHH-8662" )
public void testProxiesInCollections() throws Exception {
Session s = openSession();
s.beginTransaction();
@ -4847,7 +4846,8 @@ public class FooBarTest extends LegacyTestCase {
BarProxy b1 = (BarProxy) i.next();
BarProxy b2 = (BarProxy) i.next();
assertTrue( ( b1==barprox && !(b2 instanceof HibernateProxy) ) || ( b2==barprox && !(b1 instanceof HibernateProxy) ) ); //one-to-many
assertTrue( baz.getFooArray()[0] instanceof HibernateProxy ); //many-to-many
// <many-to-many fetch="select" is deprecated by HHH-8662; so baz.getFooArray()[0] should not be a HibernateProxy.
assertFalse( baz.getFooArray()[0] instanceof HibernateProxy ); //many-to-many
assertTrue( baz.getFooArray()[1]==bar2prox );
if ( !isOuterJoinFetchingDisabled() ) assertTrue( !(baz.getFooBag().iterator().next() instanceof HibernateProxy) ); //many-to-many outer-join="true"
assertTrue( !(baz.getFooSet().iterator().next() instanceof HibernateProxy) ); //one-to-many