Search in sources :

Example 1 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class LoadingSmokeTests method testBasicLoad.

@Test
public void testBasicLoad(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        final BasicEntity loaded = session.byId(BasicEntity.class).getReference(1);
        assertThat(loaded, notNullValue());
        assertThat(Hibernate.isInitialized(loaded), is(false));
    });
}
Also used : BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 2 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class LoadingSmokeTests method testBasicGet.

@Test
public void testBasicGet(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        final BasicEntity gotten = session.byId(BasicEntity.class).load(1);
        assertThat(gotten, notNullValue());
        assertThat(Hibernate.isInitialized(gotten), is(true));
        assertThat(gotten.getId(), is(1));
        assertThat(gotten.getData(), is("first"));
        final AbstractEntityPersister entityDescriptor = (AbstractEntityPersister) session.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(BasicEntity.class);
        final SingleIdEntityLoader singleIdEntityLoader = entityDescriptor.getSingleIdEntityLoader();
        assertThat(singleIdEntityLoader, instanceOf(SingleIdEntityLoaderStandardImpl.class));
        assertThat(((SingleIdEntityLoaderStandardImpl) singleIdEntityLoader).getNonReusablePlansGenerated().get(), is(0));
    });
}
Also used : SingleIdEntityLoader(org.hibernate.loader.ast.spi.SingleIdEntityLoader) SingleIdEntityLoaderStandardImpl(org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 3 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class HqlUpdateExecutionTests method testSimpleRestrictedUpdateWithData.

@Test
public void testSimpleRestrictedUpdateWithData(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        session.save(new BasicEntity(1, "abc"));
        session.save(new BasicEntity(2, "def"));
    });
    scope.inTransaction(session -> {
        final int rows = session.createQuery("update BasicEntity set data = :val where data = :filter").setParameter("val", "xyz").setParameter("filter", "abc").executeUpdate();
        assertThat(rows, is(1));
    });
    scope.inTransaction(session -> {
        final BasicEntity basicEntity = session.get(BasicEntity.class, 1);
        assertThat(basicEntity.getData(), is("xyz"));
        final BasicEntity basicEntity2 = session.get(BasicEntity.class, 2);
        assertThat(basicEntity2.getData(), is("def"));
    });
    scope.inTransaction(session -> {
        final int rows = session.createQuery("delete BasicEntity").executeUpdate();
        assertThat(rows, is(2));
    });
}
Also used : BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test) JoinedInheritanceTest(org.hibernate.orm.test.mapping.inheritance.joined.JoinedInheritanceTest)

Example 4 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class MultiIdEntityLoadTests method prepareTestData.

@BeforeEach
public void prepareTestData(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        final BasicEntity first = new BasicEntity(1, "first");
        final BasicEntity second = new BasicEntity(2, "second");
        final BasicEntity third = new BasicEntity(3, "third");
        session.save(first);
        session.save(second);
        session.save(third);
        session.save(new EntityWithAggregateId(new EntityWithAggregateId.Key("abc", "def"), "ghi"));
        session.save(new EntityWithAggregateId(new EntityWithAggregateId.Key("123", "456"), "789"));
    });
}
Also used : EntityWithAggregateId(org.hibernate.testing.orm.domain.gambit.EntityWithAggregateId) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class ILikeCriteriaTest method prepareData.

@BeforeEach
public void prepareData(SessionFactoryScope scope) {
    scope.inTransaction(em -> {
        BasicEntity be1 = new BasicEntity(1, "Product_one");
        em.persist(be1);
        BasicEntity be2 = new BasicEntity(2, "proDUct two");
        em.persist(be2);
        BasicEntity be3 = new BasicEntity(3, "Product three");
        em.persist(be3);
        BasicEntity be4 = new BasicEntity(4, "pROducT four");
        em.persist(be4);
        BasicEntity be5 = new BasicEntity(5, "Product five");
        em.persist(be5);
        BasicEntity be6 = new BasicEntity(6, "Prodact six");
        em.persist(be6);
        BasicEntity be7 = new BasicEntity(7, "prodACt seven");
        em.persist(be7);
        BasicEntity be8 = new BasicEntity(8, "Prod_act eight");
        em.persist(be8);
        BasicEntity be9 = new BasicEntity(9, "prod_ACt nine");
        em.persist(be9);
    });
}
Also used : BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BasicEntity (org.hibernate.testing.orm.domain.gambit.BasicEntity)44 Test (org.junit.jupiter.api.Test)39 HibernateCriteriaBuilder (org.hibernate.query.criteria.HibernateCriteriaBuilder)23 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)15 CriteriaQuery (jakarta.persistence.criteria.CriteriaQuery)11 List (java.util.List)8 Query (org.hibernate.query.Query)8 Tuple (jakarta.persistence.Tuple)6 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Collection (java.util.Collection)2 JoinedInheritanceTest (org.hibernate.orm.test.mapping.inheritance.joined.JoinedInheritanceTest)2 StatisticsImplementor (org.hibernate.stat.spi.StatisticsImplementor)2 SkipForDialect (org.hibernate.testing.SkipForDialect)2 EntityWithManyToOneJoinTable (org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable)2 SimpleEntity (org.hibernate.testing.orm.domain.gambit.SimpleEntity)2 RequiresDialect (org.hibernate.testing.orm.junit.RequiresDialect)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Selection (jakarta.persistence.criteria.Selection)1 ArrayList (java.util.ArrayList)1 SingleIdEntityLoaderStandardImpl (org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl)1