Skip to content

Commit f75c7ef

Browse files
committed
HHH-7436 : Add support for many-to-many associations to new metamodel
HHH-7436 : Add support for many-to-many associations to new metamodel HHH-7436 : Add support for many-to-many associations to new metamodel
1 parent 61039c6 commit f75c7ef

File tree

41 files changed

+547
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+547
-97
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java

Lines changed: 275 additions & 46 deletions
Large diffs are not rendered by default.

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToManyPluralAttributeElementSourceImpl.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
3333
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
3434
import org.hibernate.metamodel.spi.binding.CascadeType;
35+
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
3536
import org.hibernate.metamodel.spi.source.ManyToManyPluralAttributeElementSource;
3637
import org.hibernate.metamodel.spi.source.RelationalValueSource;
3738

@@ -68,7 +69,7 @@ public Collection<String> getReferencedColumnNames() {
6869
}
6970

7071
@Override
71-
public List<RelationalValueSource> getValueSources() {
72+
public List<RelationalValueSource> relationalValueSources() {
7273
List<RelationalValueSource> valueSources = new ArrayList<RelationalValueSource>();
7374
// todo
7475
return valueSources;
@@ -93,6 +94,11 @@ public String getExplicitForeignKeyName() {
9394
return associationAttribute.getInverseForeignKeyName();
9495
}
9596

97+
@Override
98+
public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() {
99+
return null; //To change body of implemented methods use File | Settings | File Templates.
100+
}
101+
96102
@Override
97103
public boolean isUnique() {
98104
return false; //To change body of implemented methods use File | Settings | File Templates.
@@ -117,6 +123,21 @@ public boolean fetchImmediately() {
117123
public Nature getNature() {
118124
return Nature.MANY_TO_MANY;
119125
}
126+
127+
@Override
128+
public boolean areValuesIncludedInInsertByDefault() {
129+
return true;
130+
}
131+
132+
@Override
133+
public boolean areValuesIncludedInUpdateByDefault() {
134+
return true;
135+
}
136+
137+
@Override
138+
public boolean areValuesNullableByDefault() {
139+
return false;
140+
}
120141
}
121142

122143

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractEntitySourceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ protected void processBagAttributes(List<AttributeSource> results,
287287

288288

289289
private Set<SecondaryTableSource> buildSecondaryTables() {
290-
if ( ! JoinElementSource.class.isInstance( entityElement ) ) {
291-
return Collections.emptySet();
292-
}
290+
//if ( ! JoinElementSource.class.isInstance( entityElement ) ) {
291+
// return Collections.emptySet();
292+
//}
293293

294294
final Set<SecondaryTableSource> secondaryTableSources = new HashSet<SecondaryTableSource>();
295295
for ( JaxbJoinElement joinElement : ( (JoinElementSource) entityElement ).getJoin() ) {

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToManyPluralAttributeElementSourceImpl.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
import org.hibernate.internal.util.StringHelper;
3232
import org.hibernate.jaxb.spi.hbm.JaxbColumnElement;
3333
import org.hibernate.jaxb.spi.hbm.JaxbManyToManyElement;
34+
import org.hibernate.metamodel.spi.relational.Value;
3435
import org.hibernate.metamodel.spi.source.ManyToManyPluralAttributeElementSource;
3536
import org.hibernate.metamodel.spi.source.RelationalValueSource;
3637

3738
/**
3839
* @author Steve Ebersole
40+
* @author Gail Badner
3941
*/
4042
public class ManyToManyPluralAttributeElementSourceImpl
4143
extends AbstractHbmSourceNode
@@ -113,7 +115,7 @@ public Collection<String> getReferencedColumnNames() {
113115
}
114116

115117
@Override
116-
public List<RelationalValueSource> getValueSources() {
118+
public List<RelationalValueSource> relationalValueSources() {
117119
return valueSources;
118120
}
119121

@@ -127,6 +129,13 @@ public String getExplicitForeignKeyName() {
127129
return manyToManyElement.getForeignKey();
128130
}
129131

132+
@Override
133+
public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() {
134+
return manyToManyElement.getPropertyRef() == null
135+
? null
136+
: new JoinColumnResolutionDelegateImpl();
137+
}
138+
130139
@Override
131140
public boolean isUnique() {
132141
return manyToManyElement.isUnique();
@@ -165,4 +174,32 @@ public boolean fetchImmediately() {
165174
return "true".equals( value );
166175
}
167176
}
177+
178+
@Override
179+
public boolean areValuesIncludedInInsertByDefault() {
180+
return true;
181+
}
182+
183+
@Override
184+
public boolean areValuesIncludedInUpdateByDefault() {
185+
return true;
186+
}
187+
188+
@Override
189+
public boolean areValuesNullableByDefault() {
190+
return false;
191+
}
192+
193+
public class JoinColumnResolutionDelegateImpl implements JoinColumnResolutionDelegate {
194+
@Override
195+
public String getReferencedAttributeName() {
196+
return manyToManyElement.getPropertyRef();
197+
}
198+
199+
@Override
200+
public List<Value> getJoinColumns(JoinColumnResolutionContext context) {
201+
return context.resolveRelationalValuesForAttribute( manyToManyElement.getPropertyRef() );
202+
}
203+
}
204+
168205
}

hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,7 @@ public boolean hasSubselectLoadableCollections() {
407407
return hasSubselectLoadableCollections;
408408
}
409409

410-
/* package-protected */
411-
void setSubselectLoadableCollections(boolean hasSubselectLoadableCollections) {
410+
public void setSubselectLoadableCollections(boolean hasSubselectLoadableCollections) {
412411
this.hasSubselectLoadableCollections = hasSubselectLoadableCollections;
413412
}
414413

hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToManyPluralAttributeElementBinding.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ManyToManyPluralAttributeElementBinding extends AbstractPluralAttri
3939
private String manyToManyWhere;
4040
private String manyToManyOrderBy;
4141
// TODO: really should have value defined (which defines table), but may not know
42-
private Value value;
42+
List<RelationalValueBinding> relationalValueBindings;
4343

4444
ManyToManyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
4545
super( binding );
@@ -52,7 +52,11 @@ public Nature getNature() {
5252

5353
@Override
5454
public List<RelationalValueBinding> getRelationalValueBindings() {
55-
return null; //To change body of implemented methods use File | Settings | File Templates.
55+
return relationalValueBindings;
56+
}
57+
58+
public void setRelationalValueBindings(List<RelationalValueBinding> relationalValueBindings) {
59+
this.relationalValueBindings = relationalValueBindings;
5660
}
5761

5862
public String getManyToManyWhere() {
@@ -70,12 +74,4 @@ public String getManyToManyOrderBy() {
7074
public void setManyToManyOrderBy(String manyToManyOrderBy) {
7175
this.manyToManyOrderBy = manyToManyOrderBy;
7276
}
73-
74-
public Value getValue() {
75-
return value;
76-
}
77-
78-
public void setValue(Value value) {
79-
this.value = value;
80-
}
8177
}

hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/ManyToManyPluralAttributeElementSource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929
/**
3030
* @author Steve Ebersole
3131
*/
32-
public interface ManyToManyPluralAttributeElementSource extends PluralAttributeElementSource, CascadeStyleSource {
32+
public interface ManyToManyPluralAttributeElementSource
33+
extends PluralAttributeElementSource, CascadeStyleSource, RelationalValueSourceContainer, ForeignKeyContributingSource {
3334
public String getReferencedEntityName();
3435

3536
public String getReferencedEntityAttributeName();
3637

3738
public Collection<String> getReferencedColumnNames();
3839

39-
public List<RelationalValueSource> getValueSources(); // these describe the "outgoing" link
40+
public List<RelationalValueSource> relationalValueSources(); // these describe the "outgoing" link
4041

4142
public boolean isNotFoundAnException();
4243

hibernate-core/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.hibernate.mapping.Collection;
3636
import org.hibernate.mapping.Component;
3737
import org.hibernate.mapping.Formula;
38-
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
3938
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
4039
import org.hibernate.type.StandardBasicTypes;
4140

hibernate-core/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
/**
3636
* @author Steve Ebersole
3737
*/
38-
@FailureExpectedWithNewMetamodel
3938
public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
4039
@Override
4140
public String[] getMappings() {

hibernate-core/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetCollectionEventTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
*
3434
* @author Gail Badner
3535
*/
36-
@FailureExpectedWithNewMetamodel
3736
public class BidirectionalManyToManyBagToSetCollectionEventTest extends AbstractAssociationCollectionEventTest {
3837
@Override
3938
public String[] getMappings() {

hibernate-core/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*
3434
* @author Gail Badner
3535
*/
36-
@FailureExpectedWithNewMetamodel
36+
//@FailureExpectedWithNewMetamodel
3737
public class BidirectionalManyToManySetToSetCollectionEventTest extends AbstractAssociationCollectionEventTest {
3838
@Override
3939
public String[] getMappings() {

hibernate-core/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/**
3737
* @author Gail Badner
3838
*/
39-
@FailureExpectedWithNewMetamodel
39+
//@FailureExpectedWithNewMetamodel
4040
public class UnidirectionalManyToManyBagCollectionEventTest extends AbstractAssociationCollectionEventTest {
4141
@Override
4242
public String[] getMappings() {

hibernate-core/src/test/java/org/hibernate/test/exception/SQLExceptionConversionTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
*
4646
* @author Steve Ebersole
4747
*/
48-
@FailureExpectedWithNewMetamodel
4948
public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
5049
@Override
5150
public String[] getMappings() {

hibernate-core/src/test/java/org/hibernate/test/immutable/entitywithmutablecollection/inverse/EntityWithInverseManyToManyTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
/**
3030
* @author Gail Badner
3131
*/
32-
@FailureExpectedWithNewMetamodel
3332
public class EntityWithInverseManyToManyTest extends AbstractEntityWithManyToManyTest {
3433
@Override
3534
public String[] getMappings() {

hibernate-core/src/test/java/org/hibernate/test/immutable/entitywithmutablecollection/inverse/EntityWithInverseOneToManyJoinTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@
2323
*/
2424
package org.hibernate.test.immutable.entitywithmutablecollection.inverse;
2525

26+
import org.junit.Test;
27+
2628
import org.hibernate.dialect.CUBRIDDialect;
2729
import org.hibernate.test.immutable.entitywithmutablecollection.AbstractEntityWithOneToManyTest;
2830
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
2931
import org.hibernate.testing.SkipForDialect;
32+
import org.hibernate.testing.Skip;
3033

3134
/**
3235
* @author Gail Badner
3336
*/
37+
38+
// The overridden tests are known to pass because one-to-many on a join table
39+
// is not built properly due to HHH-6391. These they are skipped for now.
40+
// When HHH-6391 is fixed, the skipped (overridden) tests should be removed.
3441
@FailureExpectedWithNewMetamodel
3542
@SkipForDialect(
3643
value = CUBRIDDialect.class,
@@ -42,4 +49,28 @@ public class EntityWithInverseOneToManyJoinTest extends AbstractEntityWithOneToM
4249
public String[] getMappings() {
4350
return new String[] { "immutable/entitywithmutablecollection/inverse/ContractVariationOneToManyJoin.hbm.xml" };
4451
}
52+
53+
// TODO: HHH-6391 is fixed, this (overridden) test should be removed.
54+
@Test
55+
@Override
56+
@Skip( condition = Skip.AlwaysSkip.class,message = "skip until HHH-6391 is fixed.")
57+
public void testDeleteOneToManyOrphan() {
58+
super.testDeleteOneToManyOrphan();
59+
}
60+
61+
// TODO: HHH-6391 is fixed, this (overridden) test should be removed.
62+
@Test
63+
@Override
64+
@Skip( condition = Skip.AlwaysSkip.class,message = "skip until HHH-6391 is fixed.")
65+
public void testRemoveOneToManyOrphanUsingMerge() {
66+
super.testRemoveOneToManyOrphanUsingMerge();
67+
}
68+
69+
// TODO: HHH-6391 is fixed, this (overridden) test should be removed.
70+
@Test
71+
@Override
72+
@Skip( condition = Skip.AlwaysSkip.class,message = "skip until HHH-6391 is fixed.")
73+
public void testRemoveOneToManyOrphanUsingUpdate() {
74+
super.testRemoveOneToManyOrphanUsingUpdate();
75+
}
4576
}

hibernate-core/src/test/java/org/hibernate/test/immutable/entitywithmutablecollection/inverse/EntityWithInverseOneToManyTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,24 @@
2323
*/
2424
package org.hibernate.test.immutable.entitywithmutablecollection.inverse;
2525

26+
import org.junit.Test;
27+
2628
import org.hibernate.test.immutable.entitywithmutablecollection.AbstractEntityWithOneToManyTest;
2729
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
2830

2931
/**
3032
* @author Gail Badner
3133
*/
32-
@FailureExpectedWithNewMetamodel
3334
public class EntityWithInverseOneToManyTest extends AbstractEntityWithOneToManyTest {
3435
@Override
3536
public String[] getMappings() {
3637
return new String[] { "immutable/entitywithmutablecollection/inverse/ContractVariation.hbm.xml" };
3738
}
39+
40+
@Test
41+
@Override
42+
@FailureExpectedWithNewMetamodel
43+
public void testOneToManyCollectionOptimisticLockingWithUpdate() {
44+
super.testOneToManyCollectionOptimisticLockingWithUpdate();
45+
}
3846
}

hibernate-core/src/test/java/org/hibernate/test/immutable/entitywithmutablecollection/inverse/VersionedEntityWithInverseManyToManyTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
/**
3030
* @author Gail Badner
3131
*/
32-
@FailureExpectedWithNewMetamodel
3332
public class VersionedEntityWithInverseManyToManyTest extends AbstractEntityWithManyToManyTest {
3433
@Override
3534
public String[] getMappings() {

hibernate-core/src/test/java/org/hibernate/test/immutable/entitywithmutablecollection/inverse/VersionedEntityWithInverseOneToManyFailureExpectedTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
*
3535
* These tests reproduce HHH-4992.
3636
*/
37-
@FailureExpectedWithNewMetamodel
3837
public class VersionedEntityWithInverseOneToManyFailureExpectedTest extends AbstractEntityWithOneToManyTest {
3938
@Override
4039
public String[] getMappings() {
@@ -90,4 +89,11 @@ public void testRemoveOneToManyElementUsingUpdate() {
9089
public void testRemoveOneToManyElementUsingMerge() {
9190
super.testRemoveOneToManyElementUsingMerge();
9291
}
92+
93+
@Test
94+
@Override
95+
@FailureExpectedWithNewMetamodel
96+
public void testOneToManyCollectionOptimisticLockingWithUpdate() {
97+
super.testOneToManyCollectionOptimisticLockingWithUpdate();
98+
}
9399
}

0 commit comments

Comments
 (0)