1010
1111import org .hibernate .generator .Generator ;
1212import org .hibernate .generator .GeneratorCreationContext ;
13+ import org .hibernate .id .CompositeNestedGeneratedValueGenerator ;
1314import org .hibernate .id .Configurable ;
1415import org .hibernate .id .IdentifierGenerator ;
1516import org .hibernate .id .SelectGenerator ;
1819import org .hibernate .id .enhanced .SequenceStyleGenerator ;
1920import org .hibernate .id .enhanced .TableGenerator ;
2021import org .hibernate .id .enhanced .TableStructure ;
22+ import org .hibernate .mapping .Component ;
2123import org .hibernate .mapping .GeneratorCreator ;
2224import org .hibernate .mapping .PersistentClass ;
2325import org .hibernate .mapping .SimpleValue ;
2426import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
2527import org .hibernate .persister .entity .EntityPersister ;
2628import org .hibernate .reactive .id .ReactiveIdentifierGenerator ;
2729import org .hibernate .reactive .id .impl .EmulatedSequenceReactiveIdentifierGenerator ;
30+ import org .hibernate .reactive .id .impl .ReactiveCompositeNestedGeneratedValueGenerator ;
2831import org .hibernate .reactive .id .impl .ReactiveGeneratorWrapper ;
2932import org .hibernate .reactive .id .impl .ReactiveSequenceIdentifierGenerator ;
3033import org .hibernate .reactive .id .impl .TableReactiveIdentifierGenerator ;
@@ -67,12 +70,9 @@ private static Generator buildIdGenerator(
6770 return existing ;
6871 }
6972 else {
70- SimpleValue identifier = (SimpleValue ) persistentClass .getIdentifier ();
71- GeneratorCreator customIdGeneratorCreator = identifier .getCustomIdGeneratorCreator ();
72- identifier .setCustomIdGeneratorCreator ( context -> {
73- Generator generator = customIdGeneratorCreator .createGenerator ( context );
74- return augmentWithReactiveGenerator ( generator , context , creationContext );
75- } );
73+ final SimpleValue identifier = (SimpleValue ) persistentClass .getIdentifier ();
74+ setCustomIdGenerator ( persistentClass , creationContext , identifier );
75+
7676 final Generator idgenerator = identifier
7777 // returns the cached Generator if it was already created
7878 .createGenerator (
@@ -86,12 +86,35 @@ private static Generator buildIdGenerator(
8686 }
8787 }
8888
89+ private static void setCustomIdGenerator (
90+ PersistentClass persistentClass ,
91+ RuntimeModelCreationContext creationContext ,
92+ SimpleValue identifier ) {
93+ final GeneratorCreator customIdGeneratorCreator = identifier .getCustomIdGeneratorCreator ();
94+ if ( identifier instanceof Component component ) {
95+ final Generator componentIdentifierGenerator = component .createGenerator (
96+ creationContext .getDialect (),
97+ persistentClass .getRootClass (),
98+ persistentClass .getIdentifierProperty (),
99+ creationContext .getGeneratorSettings ()
100+ );
101+ identifier .setCustomIdGeneratorCreator ( context ->
102+ augmentWithReactiveGenerator ( componentIdentifierGenerator , context , creationContext )
103+ );
104+ }
105+ else {
106+ identifier .setCustomIdGeneratorCreator ( context ->
107+ augmentWithReactiveGenerator ( customIdGeneratorCreator .createGenerator ( context ), context , creationContext )
108+ );
109+ }
110+ }
111+
89112 public static Generator augmentWithReactiveGenerator (
90113 Generator generator ,
91114 GeneratorCreationContext creationContext ,
92115 RuntimeModelCreationContext runtimeModelCreationContext ) {
93- if ( generator instanceof SequenceStyleGenerator ) {
94- final DatabaseStructure structure = ( ( SequenceStyleGenerator ) generator ) .getDatabaseStructure ();
116+ if ( generator instanceof SequenceStyleGenerator sequenceStyleGenerator ) {
117+ final DatabaseStructure structure = sequenceStyleGenerator .getDatabaseStructure ();
95118 if ( structure instanceof TableStructure ) {
96119 return initialize ( (IdentifierGenerator ) generator , new EmulatedSequenceReactiveIdentifierGenerator ( (TableStructure ) structure , runtimeModelCreationContext ), creationContext );
97120 }
@@ -100,16 +123,28 @@ public static Generator augmentWithReactiveGenerator(
100123 }
101124 throw LOG .unknownStructureType ();
102125 }
103- if ( generator instanceof TableGenerator ) {
126+ if ( generator instanceof TableGenerator tableGenerator ) {
104127 return initialize (
105128 (IdentifierGenerator ) generator ,
106- new TableReactiveIdentifierGenerator ( ( TableGenerator ) generator , runtimeModelCreationContext ),
129+ new TableReactiveIdentifierGenerator ( tableGenerator , runtimeModelCreationContext ),
107130 creationContext
108131 );
109132 }
110133 if ( generator instanceof SelectGenerator ) {
111134 throw LOG .selectGeneratorIsNotSupportedInHibernateReactive ();
112135 }
136+ if ( generator instanceof CompositeNestedGeneratedValueGenerator compositeNestedGeneratedValueGenerator ) {
137+ final ReactiveCompositeNestedGeneratedValueGenerator reactiveCompositeNestedGeneratedValueGenerator = new ReactiveCompositeNestedGeneratedValueGenerator (
138+ compositeNestedGeneratedValueGenerator ,
139+ creationContext ,
140+ runtimeModelCreationContext
141+ );
142+ return initialize (
143+ (IdentifierGenerator ) generator ,
144+ reactiveCompositeNestedGeneratedValueGenerator ,
145+ creationContext
146+ );
147+ }
113148 //nothing to do
114149 return generator ;
115150 }
0 commit comments