@@ -116,20 +116,22 @@ public CollectionBatchLoaderArrayParam(
116116 .buildSelectTranslator ( getSessionFactory (), sqlSelect )
117117 .translate ( JdbcParameterBindings .NO_BINDINGS , QueryOptions .NONE );
118118 }
119+
119120 @ Override
120121 public PersistentCollection <?> load (Object keyBeingLoaded , SharedSessionContractImplementor session ) {
121122 final ForeignKeyDescriptor keyDescriptor = getLoadable ().getKeyDescriptor ();
122- if ( keyDescriptor .isEmbedded () ) {
123+ if ( keyDescriptor .isEmbedded ()
124+ || keyDescriptor .getKeyPart ().getSingleJdbcMapping ().getValueConverter () != null ) {
123125 assert keyDescriptor .getJdbcTypeCount () == 1 ;
124- return loadEmbeddable ( keyBeingLoaded , session , keyDescriptor );
126+ return loadWithConversion ( keyBeingLoaded , session , keyDescriptor );
125127 }
126128 else {
127129 return super .load ( keyBeingLoaded , session );
128130 }
129131
130132 }
131133
132- private PersistentCollection <?> loadEmbeddable (
134+ private PersistentCollection <?> loadWithConversion (
133135 Object keyBeingLoaded ,
134136 SharedSessionContractImplementor session ,
135137 ForeignKeyDescriptor keyDescriptor ) {
@@ -149,14 +151,14 @@ private PersistentCollection<?> loadEmbeddable(
149151 .getComponentType (),
150152 length
151153 );
152- final Object [] embeddedKeys = (Object []) Array .newInstance ( keyDomainType , length );
154+ final Object [] domainKeys = (Object []) Array .newInstance ( keyDomainType , length );
153155 session .getPersistenceContextInternal ().getBatchFetchQueue ()
154156 .collectBatchLoadableCollectionKeys (
155157 length ,
156158 (index , key ) ->
157159 keyDescriptor .forEachJdbcValue ( key , (i , value , jdbcMapping ) -> {
158160 keysToInitialize [index ] = value ;
159- embeddedKeys [index ] = key ;
161+ domainKeys [index ] = key ;
160162 }, session )
161163 ,
162164 keyBeingLoaded ,
@@ -171,7 +173,7 @@ private PersistentCollection<?> loadEmbeddable(
171173
172174 initializeKeys ( keyBeingLoaded , keys , session );
173175
174- for ( Object initializedKey : embeddedKeys ) {
176+ for ( Object initializedKey : domainKeys ) {
175177 if ( initializedKey != null ) {
176178 finishInitializingKey ( initializedKey , session );
177179 }
@@ -231,25 +233,9 @@ void finishInitializingKeys(Object[] keys, SharedSessionContractImplementor sess
231233
232234 @ Override
233235 Object [] resolveKeysToInitialize (Object keyBeingLoaded , SharedSessionContractImplementor session ) {
234- final ForeignKeyDescriptor keyDescriptor = getLoadable ().getKeyDescriptor ();
235- if ( keyDescriptor .isEmbedded ()){
236- assert keyDescriptor .getJdbcTypeCount () == 1 ;
237- final int length = getDomainBatchSize ();
238- final Object [] keysToInitialize = (Object []) Array .newInstance ( keyDescriptor .getSingleJdbcMapping ().getJdbcJavaType ().getJavaTypeClass (), length );
239- session .getPersistenceContextInternal ().getBatchFetchQueue ()
240- .collectBatchLoadableCollectionKeys (
241- length ,
242- (index , key ) ->
243- keyDescriptor .forEachJdbcValue ( key , (i , value , jdbcMapping ) -> {
244- keysToInitialize [index ] = value ;
245- }, session )
246- ,
247- keyBeingLoaded ,
248- getLoadable ()
249- );
250- // now trim down the array to the number of keys we found
251- return trimIdBatch ( length , keysToInitialize );
252- }
236+ assert !getLoadable ().getKeyDescriptor ().isEmbedded ()
237+ && getLoadable ().getKeyDescriptor ().getKeyPart ().getSingleJdbcMapping ().getValueConverter () == null
238+ : "Should use loadWithConversion() instead" ;
253239 return super .resolveKeysToInitialize ( keyBeingLoaded , session );
254240 }
255241}
0 commit comments