Search in sources :

Example 6 with FailureExpected

use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.

the class MappedSuperclassWithOverriddenAttributeTest method testStaticMetamodelOverridden.

@Test
@FailureExpected(jiraKey = "HHH-11078")
public void testStaticMetamodelOverridden() {
    EntityManagerFactory emf = TestingEntityManagerFactoryGenerator.generateEntityManagerFactory(AvailableSettings.LOADED_CLASSES, Arrays.asList(Product2.class));
    try {
        assertNotNull(Product1_.overridenName, "'Product1_.overridenName' should not be null)");
        assertNotNull(Product2_.overridenName, "'Product2_.overridenName' should not be null)");
    // is null
    } finally {
        emf.close();
    }
}
Also used : EntityManagerFactory(jakarta.persistence.EntityManagerFactory) Test(org.junit.jupiter.api.Test) BaseUnitTest(org.hibernate.testing.orm.junit.BaseUnitTest) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Example 7 with FailureExpected

use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.

the class SelectionQueryExampleTests method namedQueryTest.

@Test
@FailureExpected(reason = "Illegal selection query")
public void namedQueryTest(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        // tag::example-hql-named-selection-query-query[]
        // cannot be validated until execution
        Query query = session.getNamedQuery("delete_Person");
        query.getResultList();
    // end::example-hql-named-selection-query-query[]
    });
}
Also used : Query(org.hibernate.query.Query) SelectionQuery(org.hibernate.query.SelectionQuery) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Example 8 with FailureExpected

use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.

the class SelectionQueryExampleTests method queryTest.

@Test
@FailureExpected(reason = "Illegal selection query")
public void queryTest(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        // tag::example-hql-selection-query-query[]
        // cannot be validated until execution
        Query query = session.createQuery("delete Person");
        query.getResultList();
    // end::example-hql-selection-query-query[]
    });
}
Also used : Query(org.hibernate.query.Query) SelectionQuery(org.hibernate.query.SelectionQuery) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Example 9 with FailureExpected

use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.

the class PersistentSetTest method testCompositeElementMerging.

@Test
@FailureExpected(jiraKey = "HHH-2485")
public void testCompositeElementMerging(SessionFactoryScope scope) {
    Container container = new Container("p1");
    scope.inTransaction(session -> {
        Container.Content c1 = new Container.Content("c1");
        container.getContents().add(c1);
        session.save(container);
    });
    CollectionStatistics stats = scope.getSessionFactory().getStatistics().getCollectionStatistics(Container.class.getName() + ".contents");
    long recreateCount = stats.getRecreateCount();
    long updateCount = stats.getUpdateCount();
    container.setName("another name");
    scope.inTransaction(session -> {
        session.merge(container);
    });
    assertEquals(1, container.getContents().size());
    assertEquals(recreateCount, stats.getRecreateCount());
    assertEquals(updateCount, stats.getUpdateCount());
    scope.inTransaction(session -> {
        Container c = session.get(Container.class, container.getId());
        assertEquals(1, container.getContents().size());
        session.delete(container);
    });
}
Also used : CollectionStatistics(org.hibernate.stat.CollectionStatistics) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Example 10 with FailureExpected

use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.

the class TransientOverrideAsPersistentJoined method testCriteriaQueryByRootClassAndOverridenProperty.

@Test
@FailureExpected(jiraKey = "HHH-12981")
public void testCriteriaQueryByRootClassAndOverridenProperty(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        final CriteriaBuilder builder = session.getCriteriaBuilder();
        final CriteriaQuery<Employee> query = builder.createQuery(Employee.class);
        final Root<Employee> root = query.from(Employee.class);
        final ParameterExpression<String> parameter = builder.parameter(String.class, "title");
        final Predicate predicateEditor = builder.equal(builder.treat(root, Editor.class).get("title"), parameter);
        query.where(predicateEditor);
        final Employee editor = session.createQuery(query).setParameter("title", "Senior Editor").getSingleResult();
        assertThat(editor, instanceOf(Editor.class));
        final Predicate predicateWriter = builder.equal(builder.treat(root, Writer.class).get("title"), parameter);
        query.where(predicateWriter);
        final Employee writer = session.createQuery(query).setParameter("title", "Writing").getSingleResult();
        assertThat(writer, instanceOf(Writer.class));
        assertNotNull(((Writer) writer).getGroup());
        assertEquals(writer.getTitle(), ((Writer) writer).getGroup().getName());
    });
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) Predicate(jakarta.persistence.criteria.Predicate) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Aggregations

FailureExpected (org.hibernate.testing.orm.junit.FailureExpected)25 Test (org.junit.jupiter.api.Test)25 SQLStatementInspector (org.hibernate.testing.jdbc.SQLStatementInspector)6 JiraKey (org.hibernate.testing.orm.junit.JiraKey)6 List (java.util.List)5 TestForIssue (org.hibernate.testing.TestForIssue)4 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)3 Query (org.hibernate.query.Query)3 SelectionQuery (org.hibernate.query.SelectionQuery)3 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)2 UniqueConstraint (jakarta.persistence.UniqueConstraint)2 Date (java.util.Date)2 CollectionStatistics (org.hibernate.stat.CollectionStatistics)2 BaseUnitTest (org.hibernate.testing.orm.junit.BaseUnitTest)2 StoredProcedureQuery (jakarta.persistence.StoredProcedureQuery)1 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)1 Predicate (jakarta.persistence.criteria.Predicate)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1