File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
hibernate-core/src/main/java/org/hibernate/metamodel/mapping Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 1111import org .hibernate .metamodel .model .domain .NavigableRole ;
1212import org .hibernate .metamodel .spi .MappingMetamodelImplementor ;
1313import org .hibernate .type .BasicType ;
14+ import org .hibernate .type .descriptor .java .CharacterJavaType ;
1415import org .hibernate .type .descriptor .java .JavaType ;
16+ import org .hibernate .type .descriptor .java .StringJavaType ;
1517
1618import java .util .List ;
1719import java .util .Map ;
@@ -111,6 +113,23 @@ public DiscriminatorValueDetails getDetailsForDiscriminatorValue(Object value) {
111113 return notNullMatch ;
112114 }
113115
116+ if ( value .getClass ().isEnum () ) {
117+ final Object enumValue ;
118+ if ( getRelationalJavaType () instanceof StringJavaType ) {
119+ enumValue = ( (Enum ) value ).name ();
120+ }
121+ else if ( getRelationalJavaType () instanceof CharacterJavaType ) {
122+ enumValue = ( (Enum ) value ).name ().charAt ( 0 );
123+ }
124+ else {
125+ enumValue = ( (Enum ) value ).ordinal ();
126+ }
127+ final DiscriminatorValueDetails enumMatch = discriminatorValueToEntityNameMap .get ( enumValue );
128+ if ( enumMatch != null ) {
129+ return enumMatch ;
130+ }
131+ }
132+
114133 throw new HibernateException ( "Unrecognized discriminator value: " + value );
115134 }
116135
You can’t perform that action at this time.
0 commit comments