|
4 | 4 | */ |
5 | 5 | package org.hibernate.boot.model.source.internal.hbm; |
6 | 6 |
|
7 | | -import java.io.Serializable; |
8 | | -import java.util.ArrayList; |
9 | | -import java.util.List; |
10 | | -import java.util.Optional; |
11 | 7 |
|
12 | 8 | import org.hibernate.AssertionFailure; |
13 | 9 | import org.hibernate.boot.MappingException; |
14 | | -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmColumnType; |
15 | 10 | import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterType; |
16 | | -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmManyToOneType; |
17 | | -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType; |
18 | 11 | import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSynchronizeType; |
19 | 12 | import org.hibernate.boot.jaxb.hbm.spi.PluralAttributeInfo; |
20 | 13 | import org.hibernate.boot.model.source.spi.Caching; |
@@ -72,75 +65,11 @@ protected AbstractPluralAttributeSourceImpl( |
72 | 65 | this.attributeRole = container.getAttributeRoleBase().append( pluralAttributeJaxbMapping.getName() ); |
73 | 66 | this.attributePath = container.getAttributePathBase().append( pluralAttributeJaxbMapping.getName() ); |
74 | 67 |
|
75 | | - Optional<JaxbHbmManyToOneType> jaxbHbmManyToOneTypeOptional = Optional.empty(); |
76 | | - |
77 | | - // Our goal here is to find the inverse side of a one to many to figure out against what to join |
78 | | - if ( pluralAttributeJaxbMapping.isInverse() && pluralAttributeJaxbMapping.getOneToMany() != null && pluralAttributeJaxbMapping.getKey().getPropertyRef() == null ) { |
79 | | - String childClass = pluralAttributeJaxbMapping.getOneToMany().getClazz(); |
80 | | - |
81 | | - if ( childClass != null ) { |
82 | | - // We match by columns as defined in the key |
83 | | - final List<String> keyColumnNames; |
84 | | - if ( pluralAttributeJaxbMapping.getKey().getColumnAttribute() == null ) { |
85 | | - keyColumnNames = new ArrayList<>( pluralAttributeJaxbMapping.getKey().getColumn().size() ); |
86 | | - for ( JaxbHbmColumnType jaxbHbmColumnType : pluralAttributeJaxbMapping.getKey().getColumn() ) { |
87 | | - keyColumnNames.add( jaxbHbmColumnType.getName() ); |
88 | | - } |
89 | | - } |
90 | | - else { |
91 | | - keyColumnNames = new ArrayList<>( 1 ); |
92 | | - keyColumnNames.add( pluralAttributeJaxbMapping.getKey().getColumnAttribute() ); |
93 | | - } |
94 | | - jaxbHbmManyToOneTypeOptional = mappingDocument.getDocumentRoot().getClazz() |
95 | | - .stream() |
96 | | - .filter( (JaxbHbmRootEntityType entityType) -> childClass.equals( entityType.getName() ) ) |
97 | | - .flatMap( jaxbHbmRootEntityType -> jaxbHbmRootEntityType.getAttributes().stream() ) |
98 | | - .filter( attribute -> { |
99 | | - if ( attribute instanceof JaxbHbmManyToOneType manyToOneType ) { |
100 | | - String manyToOneTypeClass = manyToOneType.getClazz(); |
101 | | - String containerClass = container.getAttributeRoleBase().getFullPath(); |
102 | | - // Consider many to ones that have no class defined or equal the owner class of the one to many |
103 | | - if ( manyToOneTypeClass == null || manyToOneTypeClass.equals( containerClass ) ) { |
104 | | - if ( manyToOneType.getColumnAttribute() == null ) { |
105 | | - List<Serializable> columns = manyToOneType.getColumnOrFormula(); |
106 | | - if ( columns.size() != keyColumnNames.size() ) { |
107 | | - return false; |
108 | | - } |
109 | | - for ( int i = 0; i < columns.size(); i++ ) { |
110 | | - Serializable column = columns.get( i ); |
111 | | - String keyColumn = keyColumnNames.get( i ); |
112 | | - if ( !( column instanceof JaxbHbmColumnType ) || !( (JaxbHbmColumnType) column ) |
113 | | - .getName() |
114 | | - .equals( keyColumn ) ) { |
115 | | - return false; |
116 | | - } |
117 | | - } |
118 | | - } |
119 | | - else { |
120 | | - return keyColumnNames.size() == 1 && keyColumnNames.get( 0 ) |
121 | | - .equals( manyToOneType.getColumnAttribute() ); |
122 | | - } |
123 | | - return true; |
124 | | - } |
125 | | - } |
126 | | - return false; |
127 | | - }) |
128 | | - .map( JaxbHbmManyToOneType.class::cast ) |
129 | | - .findFirst(); |
130 | | - } |
131 | | - } |
132 | | - |
133 | | - this.keySource = jaxbHbmManyToOneTypeOptional |
134 | | - .map( jaxbHbmManyToOneType -> new PluralAttributeKeySourceImpl( |
135 | | - sourceMappingDocument(), |
136 | | - pluralAttributeJaxbMapping.getKey(), |
137 | | - jaxbHbmManyToOneType, |
138 | | - container |
139 | | - ) ).orElseGet( () -> new PluralAttributeKeySourceImpl( |
140 | | - sourceMappingDocument(), |
141 | | - pluralAttributeJaxbMapping.getKey(), |
142 | | - container |
143 | | - ) ); |
| 68 | + this.keySource = new PluralAttributeKeySourceImpl( |
| 69 | + sourceMappingDocument(), |
| 70 | + pluralAttributeJaxbMapping.getKey(), |
| 71 | + container |
| 72 | + ); |
144 | 73 |
|
145 | 74 | this.typeInformation = new HibernateTypeSourceImpl( pluralAttributeJaxbMapping.getCollectionType() ); |
146 | 75 |
|
|
0 commit comments