Skip to content

Commit

Permalink
[hibernate#1979] Fix support for @EmbeddedId
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Sep 16, 2024
1 parent 80e4ed9 commit 0c08e61
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* Hibernate, Relational Persistence for Idiomatic Java
*
* SPDX-License-Identifier: Apache-2.0
* Copyright: Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.reactive.metamodel.mapping.internal;

import java.util.function.BiConsumer;

import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.internal.AbstractCompositeIdentifierMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.internal.EmbeddedIdentifierMappingImpl;
import org.hibernate.reactive.sql.results.graph.embeddable.internal.ReactiveEmbeddableFetchImpl;
import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.Fetch;
import org.hibernate.sql.results.graph.FetchParent;

public class ReactiveEmbeddedIdentifierMappingImpl extends AbstractCompositeIdentifierMapping {

private final EmbeddedIdentifierMappingImpl delegate;

public ReactiveEmbeddedIdentifierMappingImpl(EmbeddedIdentifierMappingImpl delegate) {
super( delegate );
this.delegate = delegate;
}

@Override
public Fetch generateFetch(
FetchParent fetchParent,
NavigablePath fetchablePath,
FetchTiming fetchTiming,
boolean selected,
String resultVariable,
DomainResultCreationState creationState) {
return new ReactiveEmbeddableFetchImpl(
fetchablePath,
this,
fetchParent,
fetchTiming,
selected,
creationState
);
}

@Override
public EmbeddableMappingType getPartMappingType() {
return delegate.getPartMappingType();
}

@Override
public void applySqlSelections(
NavigablePath navigablePath,
TableGroup tableGroup,
DomainResultCreationState creationState) {
delegate.applySqlSelections( navigablePath, tableGroup, creationState );
}

@Override
public void applySqlSelections(
NavigablePath navigablePath,
TableGroup tableGroup,
DomainResultCreationState creationState,
BiConsumer<SqlSelection, JdbcMapping> selectionConsumer) {
delegate.applySqlSelections( navigablePath, tableGroup, creationState, selectionConsumer );
}

@Override
public EmbeddableMappingType getMappedIdEmbeddableTypeDescriptor() {
return delegate.getMappedIdEmbeddableTypeDescriptor();
}

@Override
public Nature getNature() {
return delegate.getNature();
}

@Override
public String getAttributeName() {
return delegate.getAttributeName();
}

@Override
public Object getIdentifier(Object entity) {
return delegate.getIdentifier( entity );
}

@Override
public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) {
delegate.setIdentifier( entity, id, session );
}

@Override
public String getSqlAliasStem() {
return "";
}

@Override
public String getFetchableName() {
return delegate.getFetchableName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.internal.EmbeddedIdentifierMappingImpl;
import org.hibernate.metamodel.mapping.internal.GeneratedValuesProcessor;
import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper;
import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
Expand All @@ -56,6 +57,7 @@
import org.hibernate.reactive.loader.ast.spi.ReactiveSingleUniqueKeyEntityLoader;
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.reactive.logging.impl.LoggerFactory;
import org.hibernate.reactive.metamodel.mapping.internal.ReactiveEmbeddedIdentifierMappingImpl;
import org.hibernate.reactive.metamodel.mapping.internal.ReactivePluralAttributeMapping;
import org.hibernate.reactive.metamodel.mapping.internal.ReactiveToOneAttributeMapping;
import org.hibernate.reactive.sql.results.graph.embeddable.internal.ReactiveNonAggregatedIdentifierMappingFetch;
Expand Down Expand Up @@ -324,6 +326,9 @@ public EntityIdentifierMapping convertEntityIdentifierMapping(EntityIdentifierMa
if ( entityIdentifierMapping instanceof NonAggregatedIdentifierMappingImpl ) {
return new ReactiveNonAggregatedIdentifierMappingImpl( (NonAggregatedIdentifierMappingImpl) entityIdentifierMapping );
}
if ( entityIdentifierMapping instanceof EmbeddedIdentifierMappingImpl ) {
return new ReactiveEmbeddedIdentifierMappingImpl( (EmbeddedIdentifierMappingImpl) entityIdentifierMapping );
}
return entityIdentifierMapping;
}

Expand Down

0 comments on commit 0c08e61

Please sign in to comment.