Tests for checking multiple execution of EmbeddableInitializers
This commit is contained in:
parent
44cb271030
commit
0f46ee2466
|
@ -246,8 +246,13 @@ public class ResultSetMappingImpl implements ResultSetMapping {
|
|||
}
|
||||
}
|
||||
}
|
||||
final Map<String, LockMode> registeredLockModes = creationState.getRegisteredLockModes();
|
||||
return new JdbcValuesMappingImpl( sqlSelections, domainResults, rowSize, registeredLockModes );
|
||||
|
||||
return new JdbcValuesMappingImpl(
|
||||
sqlSelections,
|
||||
domainResults,
|
||||
rowSize,
|
||||
creationState.getRegisteredLockModes()
|
||||
);
|
||||
}
|
||||
|
||||
private static void addColumns(Set<String> aliases, Set<String> knownDuplicateAliases, String[] columns) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.hibernate.metamodel.EmbeddableRepresentationStrategy;
|
|||
import org.hibernate.property.access.spi.PropertyAccess;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.sql.results.ResultsLogger;
|
||||
import org.hibernate.sql.results.graph.AbstractFetchParentAccess;
|
||||
import org.hibernate.sql.results.graph.AssemblerCreationState;
|
||||
import org.hibernate.sql.results.graph.DomainResultAssembler;
|
||||
|
@ -139,19 +140,18 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA
|
|||
@Override
|
||||
public void resolveKey(RowProcessingState processingState) {
|
||||
// nothing to do
|
||||
EmbeddableLoadingLogger.INSTANCE.debugf( "EmbeddableInitializer#resolveKey : %s", navigablePath.getFullPath() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveInstance(RowProcessingState processingState) {
|
||||
// nothing to do
|
||||
EmbeddableLoadingLogger.INSTANCE.debugf( "EmbeddableInitializer#resolveInstance : %s", navigablePath.getFullPath() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeInstance(RowProcessingState processingState) {
|
||||
EmbeddableLoadingLogger.INSTANCE.debugf(
|
||||
"Initializing composite instance [%s]",
|
||||
navigablePath
|
||||
);
|
||||
EmbeddableLoadingLogger.INSTANCE.debugf( "Initializing composite instance [%s]", navigablePath );
|
||||
|
||||
stateInjected = false;
|
||||
|
||||
|
|
|
@ -103,12 +103,27 @@ public class ResultsHelper {
|
|||
}
|
||||
);
|
||||
|
||||
logInitializers( initializerMap );
|
||||
|
||||
//noinspection rawtypes
|
||||
return new StandardRowReader<>(
|
||||
(List) assemblers,
|
||||
initializers,
|
||||
rowTransformer
|
||||
);
|
||||
return new StandardRowReader<>( (List) assemblers, initializers, rowTransformer );
|
||||
}
|
||||
|
||||
private static void logInitializers(Map<NavigablePath, Initializer> initializerMap) {
|
||||
if ( ! ResultsLogger.DEBUG_ENABLED ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResultsLogger.LOGGER.debug( "Initializer list" );
|
||||
initializerMap.forEach( (navigablePath, initializer) -> {
|
||||
ResultsLogger.LOGGER.debugf(
|
||||
" %s -> %s@%s (%s)",
|
||||
navigablePath.getFullPath(),
|
||||
initializer,
|
||||
initializer.hashCode(),
|
||||
initializer.getInitializedPart()
|
||||
);
|
||||
} );
|
||||
}
|
||||
|
||||
public static void finalizeCollectionLoading(
|
||||
|
|
|
@ -14,14 +14,12 @@ import org.junit.jupiter.api.AfterEach;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel( annotatedClasses = { Customer.class, Order.class } )
|
||||
@SessionFactory
|
||||
public class EmbeddableInitializerTests {
|
||||
public class IdClassQueryRefTests {
|
||||
|
||||
@Test
|
||||
public void testHqlVirtualIdReferences(SessionFactoryScope scope) {
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.mapping.embeddable.initializer;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity(name = "Customer")
|
||||
@Table(name = "customers")
|
||||
public class Customer {
|
||||
@Id
|
||||
public Integer id;
|
||||
@Basic
|
||||
public String name;
|
||||
|
||||
protected Customer() {
|
||||
// for Hibernate use
|
||||
}
|
||||
|
||||
public Customer(Integer id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.mapping.embeddable.initializer;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel( annotatedClasses = { Customer.class, Order.class } )
|
||||
@SessionFactory
|
||||
public class EmbeddableInitializerTests {
|
||||
@Test
|
||||
public void testGet(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> {
|
||||
final Order order = session.get( Order.class, new OrderId( 1, 1 ) );
|
||||
|
||||
assertThat( order ).isNotNull();
|
||||
|
||||
assertThat( order.orderNumber ).isNotNull();
|
||||
assertThat( order.customer ).isNotNull();
|
||||
|
||||
assertThat( order.customer.id ).isNotNull();
|
||||
assertThat( order.customer.name ).isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuery(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> {
|
||||
session.createQuery( "from Order o where o.orderNumber = 123" ).list();
|
||||
} );
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void createTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> {
|
||||
final Customer acme = new Customer( 1, "acme" );
|
||||
final Customer spacely = new Customer( 2, "spacely" );
|
||||
session.persist( acme );
|
||||
session.persist( spacely );
|
||||
|
||||
final Order acmeOrder1 = new Order( acme, 1, 123F );
|
||||
final Order acmeOrder2 = new Order( acme, 2, 123F );
|
||||
session.persist( acmeOrder1 );
|
||||
session.persist( acmeOrder2 );
|
||||
} );
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> {
|
||||
session.createQuery( "delete Order" ).executeUpdate();
|
||||
session.createQuery( "delete Customer" ).executeUpdate();
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.mapping.embeddable.initializer;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.IdClass;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity(name = "Order")
|
||||
@Table(name = "orders")
|
||||
@IdClass( OrderId.class )
|
||||
public class Order {
|
||||
@Id
|
||||
@ManyToOne
|
||||
public Customer customer;
|
||||
|
||||
@Id
|
||||
public Integer orderNumber;
|
||||
|
||||
public Float amount;
|
||||
|
||||
protected Order() {
|
||||
// for Hibernate use
|
||||
}
|
||||
|
||||
public Order(Customer customer, Integer orderNumber, Float amount) {
|
||||
this.customer = customer;
|
||||
this.orderNumber = orderNumber;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public void setCustomer(Customer customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public Integer getOrderNumber() {
|
||||
return orderNumber;
|
||||
}
|
||||
|
||||
public void setOrderNumber(Integer orderNumber) {
|
||||
this.orderNumber = orderNumber;
|
||||
}
|
||||
|
||||
public Float getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(Float amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.mapping.embeddable.initializer;
|
||||
|
||||
public class OrderId {
|
||||
Integer customer;
|
||||
Integer orderNumber;
|
||||
|
||||
public OrderId() {
|
||||
}
|
||||
|
||||
public OrderId(Integer customer, Integer orderNumber) {
|
||||
this.customer = customer;
|
||||
this.orderNumber = orderNumber;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simplified form of {@link org.hibernate.orm.test.mapping.cid.idclass}
|
||||
* for the purpose of tracking down seemingly duplicated calls to the
|
||||
* {@link org.hibernate.sql.results.graph.embeddable.EmbeddableInitializer}
|
||||
* impls
|
||||
*/
|
||||
package org.hibernate.orm.test.mapping.embeddable.initializer;
|
Loading…
Reference in New Issue