Tests for debugging potential multiple calls to EmbeddableInstantiators
This commit is contained in:
parent
9287b97cd3
commit
087d486d6b
|
@ -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.cid.query;
|
||||||
|
|
||||||
|
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,83 @@
|
||||||
|
/*
|
||||||
|
* 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.cid.query;
|
||||||
|
|
||||||
|
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 testHqlVirtualIdReferences(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( (session) -> {
|
||||||
|
session.createQuery( "from Order o where o.orderNumber = 123" ).list();
|
||||||
|
session.createQuery( "from Order o where o.customer = 1" ).list();
|
||||||
|
session.createQuery( "from Order o where o.customer.id = 1" ).list();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHqlIdClassReferences(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( (session) -> {
|
||||||
|
session.createQuery( "from Order o where o.id.orderNumber = 123" ).list();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@FailureExpected(
|
||||||
|
reason = "Mismatched expectations - some parts of the translation expect this to be the key-many-to-one" +
|
||||||
|
" while other parts expect the basic IdClass reference"
|
||||||
|
)
|
||||||
|
public void testHqlIdClassReferencesBug(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( (session) -> {
|
||||||
|
session.createQuery( "from Order o where o.id.customer = 1" ).list();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@FailureExpected( reason = "This is an invalid query" )
|
||||||
|
public void testHqlInvalidIdClassReferences(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( (session) -> {
|
||||||
|
session.createQuery( "from Order o where o.id.customer.id = 1" ).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.cid.query;
|
||||||
|
|
||||||
|
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.cid.query;
|
||||||
|
|
||||||
|
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.cid.query;
|
Loading…
Reference in New Issue