@@ -139,37 +139,23 @@ else if ( value != null ) {
139
139
* @throws HibernateException error while getting subcomponent values
140
140
*/
141
141
private String checkSubElementsNullability (Type propertyType , Object value ) throws HibernateException {
142
- // IMPL NOTE : we currently skip checking "any" and "many to any" mappings. This is not the best solution.
143
- //
144
- // The problem I ran into with performing the checks on "any" and "many to any" mappings had to do with
145
- // cascaded saves of transient associated entities not yet having assigned the identifier (this was
146
- // specifically in the "many to any" case).
147
-
148
- if ( propertyType .isAnyType () ) {
149
- return null ;
150
- }
151
-
152
142
if ( propertyType .isComponentType () ) {
153
143
return checkComponentNullability ( value , (CompositeType ) propertyType );
154
144
}
155
145
156
146
if ( propertyType .isCollectionType () ) {
157
- //persistent collections may have components
147
+ // persistent collections may have components
158
148
final CollectionType collectionType = (CollectionType ) propertyType ;
159
149
final Type collectionElementType = collectionType .getElementType ( session .getFactory () );
160
150
161
- if ( collectionElementType .isAnyType () ) {
162
- return null ;
163
- }
164
-
165
151
if ( collectionElementType .isComponentType () ) {
166
- //check for all components values in the collection
152
+ // check for all components values in the collection
167
153
final CompositeType componentType = (CompositeType ) collectionElementType ;
168
154
final Iterator itr = CascadingActions .getLoadedElementsIterator ( session , collectionType , value );
169
155
while ( itr .hasNext () ) {
170
- final Object compValue = itr .next ();
171
- if ( compValue != null ) {
172
- return checkComponentNullability ( compValue , componentType );
156
+ final Object compositeElement = itr .next ();
157
+ if ( compositeElement != null ) {
158
+ return checkComponentNullability ( compositeElement , componentType );
173
159
}
174
160
}
175
161
}
@@ -183,29 +169,39 @@ private String checkSubElementsNullability(Type propertyType, Object value) thro
183
169
* nullability or null if none
184
170
*
185
171
* @param value component properties
186
- * @param compType component not-nullable type
172
+ * @param compositeType component not-nullable type
187
173
*
188
174
* @return property path
189
175
* @throws HibernateException error while getting subcomponent values
190
176
*/
191
- private String checkComponentNullability (Object value , CompositeType compType ) throws HibernateException {
192
- /* will check current level if some of them are not null
193
- * or sublevels if they exist
194
- */
195
- final boolean [] nullability = compType .getPropertyNullability ();
177
+ private String checkComponentNullability (Object value , CompositeType compositeType ) throws HibernateException {
178
+ // IMPL NOTE : we currently skip checking "any" and "many to any" mappings.
179
+ //
180
+ // This is not the best solution. But atm there is a mismatch between AnyType#getPropertyNullability
181
+ // and the fact that cascaded-saves for "many to any" mappings are not performed until after this nullability
182
+ // check. So the nullability check fails for transient entity elements with generated identifiers because
183
+ // the identifier is not yet generated/assigned (is null)
184
+ //
185
+ // The more correct fix would be to cascade saves of the many-to-any elements before the Nullability checking
186
+
187
+ if ( compositeType .isAnyType () ) {
188
+ return null ;
189
+ }
190
+
191
+ final boolean [] nullability = compositeType .getPropertyNullability ();
196
192
if ( nullability != null ) {
197
193
//do the test
198
- final Object [] subValues = compType .getPropertyValues ( value , session );
199
- final Type [] propertyTypes = compType .getSubtypes ();
194
+ final Object [] subValues = compositeType .getPropertyValues ( value , session );
195
+ final Type [] propertyTypes = compositeType .getSubtypes ();
200
196
for ( int i = 0 ; i < subValues .length ; i ++ ) {
201
197
final Object subValue = subValues [i ];
202
198
if ( !nullability [i ] && subValue ==null ) {
203
- return compType .getPropertyNames ()[i ];
199
+ return compositeType .getPropertyNames ()[i ];
204
200
}
205
201
else if ( subValue != null ) {
206
202
final String breakProperties = checkSubElementsNullability ( propertyTypes [i ], subValue );
207
203
if ( breakProperties != null ) {
208
- return buildPropertyPath ( compType .getPropertyNames ()[i ], breakProperties );
204
+ return buildPropertyPath ( compositeType .getPropertyNames ()[i ], breakProperties );
209
205
}
210
206
}
211
207
}
0 commit comments