Introduce `VirtualIdEmbeddable` and `IdClassEmbeddable` + instantiators

- Clean up Component Type, removing as many calls to its tuplizer as possible atm
- Clean up ManagedMappingType, EntityPersister, etc - mainly work around getting and setting value(s)

Still need to
  - integrate embedded forms.  `VirtualIdEmbeddable` does not really need it as it can use the id-mapping itself as the embedded form.  But `IdClassEmbedded` should really be integrated
  - integrate `VirtualKeyEmbeddable` and `VirtualKeyEmbedded` for use as inverse composite fks
  - share `#finishInit` handling for `EmbeddableMappingType`, `VirtualIdEmbeddable` and `IdClassEmbeddable`
  - ability to use the containing composite owner as the parent of a composite (legacy behavior is to always use the "first" entity
  - clean up ComponentType, esp wrt its use of ComponentTuplizer
This commit is contained in:
Steve Ebersole 2021-12-01 11:32:34 -06:00
parent b23c2f48c1
commit dc744844e4
2 changed files with 50 additions and 61 deletions

View File

@ -41,6 +41,14 @@ public class NestedIdClassTests {
}); });
} }
@Test
public void testHqlIdAttributeReference(SessionFactoryScope scope) {
scope.inTransaction( (session) -> {
session.createQuery( "from Payment p where p.order.orderNumber = '123'" ).list();
session.createQuery( "from Payment p where p.id.order.orderNumber = '123'" ).list();
});
}
@BeforeEach @BeforeEach
public void createTestData(SessionFactoryScope scope) { public void createTestData(SessionFactoryScope scope) {
scope.inTransaction( (session) -> { scope.inTransaction( (session) -> {

View File

@ -19,8 +19,13 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.FailureExpected; import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.transaction.TransactionUtil2; import org.hibernate.testing.transaction.TransactionUtil2;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
/** /**
@ -29,74 +34,50 @@ import org.junit.jupiter.api.Test;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
@DomainModel( annotatedClasses = {
SmokeTests.SystemAccess.class,
SmokeTests.Order.class,
SmokeTests.LineItem.class
} )
@SessionFactory
public class SmokeTests { public class SmokeTests {
@Test @Test
@FailureExpected( reason = "See org.hibernate.metamodel.mapping.internal.NonAggregatedIdentifierMappingImpl#createDomainResult" ) public void simpleTest(SessionFactoryScope scope) {
public void simpleTest() { scope.inTransaction( (session) -> {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); session.createQuery( "select a from SystemAccess a" ).list();
try { } );
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources( ssr )
.addAnnotatedClass( SystemAccess.class )
.buildMetadata()
.buildSessionFactory();
TransactionUtil2.inTransaction(
sessionFactory,
session -> {
session.createQuery( "select a from SystemAccess a" ).list();
}
);
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );
}
} }
@Test @Test
@FailureExpected( reason = "Support for non-aggregated composite-ids not yet fully implemented" ) public void keyManyToOneTest(SessionFactoryScope scope) {
public void keyManyToOneTest() { scope.inTransaction( (session) -> {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); session.createQuery( "select i from LineItem i" ).list();
} );
try {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources( ssr )
.addAnnotatedClass( Order.class )
.addAnnotatedClass( LineItem.class )
.buildMetadata()
.buildSessionFactory();
TransactionUtil2.inTransaction(
sessionFactory,
session -> {
session.createQuery( "select i from LineItem i" ).list();
}
);
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );
}
} }
// @BeforeEach @BeforeEach
// public void createTestData(SessionFactoryScope scope) { public void createTestData(SessionFactoryScope scope) {
// scope.inTransaction( scope.inTransaction(
// session -> { session -> {
// final Order order = new Order( 1, "123-abc" ); final Order order = new Order( 1, "123-abc" );
// session.persist( order ); session.persist( order );
//
// session.persist( new LineItem( order, 1, "xyz", 500 ) ); session.persist( new LineItem( order, 1, "xyz", 500 ) );
// session.persist( new LineItem( order, 2, "tuv", 60 ) ); session.persist( new LineItem( order, 2, "tuv", 60 ) );
// session.persist( new LineItem( order, 3, "def", 350 ) ); session.persist( new LineItem( order, 3, "def", 350 ) );
// } }
// ); );
// } }
//
// @AfterEach @AfterEach
// public void cleanUpTestData(SessionFactoryScope scope) { public void dropTestData(SessionFactoryScope scope) {
// scope.inTransaction( scope.inTransaction(
// session -> { session -> {
// session.createQuery( "delete LineItem" ).executeUpdate(); session.createQuery( "delete LineItem" ).executeUpdate();
// session.createQuery( "delete Order" ).executeUpdate(); session.createQuery( "delete Order" ).executeUpdate();
// } }
// ); );
// } }
@Entity( name = "SystemAccess" ) @Entity( name = "SystemAccess" )
@Table( name = "`access`" ) @Table( name = "`access`" )