25
25
26
26
import java .util .Iterator ;
27
27
28
- import org .hibernate .EntityMode ;
29
28
import org .hibernate .HibernateException ;
30
29
import org .hibernate .PropertyValueException ;
31
30
import org .hibernate .bytecode .instrumentation .spi .LazyPropertyInitializer ;
@@ -139,20 +138,32 @@ else if ( value != null ) {
139
138
* @return property path
140
139
* @throws HibernateException error while getting subcomponent values
141
140
*/
142
- private String checkSubElementsNullability (final Type propertyType , final Object value )
143
- throws HibernateException {
144
- //for non null args, check for components and elements containing components
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
+
145
152
if ( propertyType .isComponentType () ) {
146
153
return checkComponentNullability ( value , (CompositeType ) propertyType );
147
154
}
148
- else if ( propertyType .isCollectionType () ) {
149
155
156
+ if ( propertyType .isCollectionType () ) {
150
157
//persistent collections may have components
151
158
final CollectionType collectionType = (CollectionType ) propertyType ;
152
159
final Type collectionElementType = collectionType .getElementType ( session .getFactory () );
160
+
161
+ if ( collectionElementType .isAnyType () ) {
162
+ return null ;
163
+ }
164
+
153
165
if ( collectionElementType .isComponentType () ) {
154
166
//check for all components values in the collection
155
-
156
167
final CompositeType componentType = (CompositeType ) collectionElementType ;
157
168
final Iterator itr = CascadingActions .getLoadedElementsIterator ( session , collectionType , value );
158
169
while ( itr .hasNext () ) {
@@ -163,6 +174,7 @@ else if ( propertyType.isCollectionType() ) {
163
174
}
164
175
}
165
176
}
177
+
166
178
return null ;
167
179
}
168
180
@@ -176,23 +188,22 @@ else if ( propertyType.isCollectionType() ) {
176
188
* @return property path
177
189
* @throws HibernateException error while getting subcomponent values
178
190
*/
179
- private String checkComponentNullability (final Object value , final CompositeType compType )
180
- throws HibernateException {
191
+ private String checkComponentNullability (Object value , CompositeType compType ) throws HibernateException {
181
192
/* will check current level if some of them are not null
182
193
* or sublevels if they exist
183
194
*/
184
195
final boolean [] nullability = compType .getPropertyNullability ();
185
- if ( nullability != null ) {
196
+ if ( nullability != null ) {
186
197
//do the test
187
- final Object [] values = compType .getPropertyValues ( value , EntityMode . POJO );
198
+ final Object [] subValues = compType .getPropertyValues ( value , session );
188
199
final Type [] propertyTypes = compType .getSubtypes ();
189
- for ( int i = 0 ; i < values .length ; i ++ ) {
190
- final Object subvalue = values [i ];
191
- if ( !nullability [i ] && subvalue ==null ) {
200
+ for ( int i = 0 ; i < subValues .length ; i ++ ) {
201
+ final Object subValue = subValues [i ];
202
+ if ( !nullability [i ] && subValue ==null ) {
192
203
return compType .getPropertyNames ()[i ];
193
204
}
194
- else if ( subvalue != null ) {
195
- final String breakProperties = checkSubElementsNullability ( propertyTypes [i ], subvalue );
205
+ else if ( subValue != null ) {
206
+ final String breakProperties = checkSubElementsNullability ( propertyTypes [i ], subValue );
196
207
if ( breakProperties != null ) {
197
208
return buildPropertyPath ( compType .getPropertyNames ()[i ], breakProperties );
198
209
}
0 commit comments