Search in sources :

Example 11 with FailureExpected

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

the class MutationQueryExampleTests method namedQueryTest.

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

Example 12 with FailureExpected

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

the class FieldAccessedNestedEmbeddableMetadataTest method testEnumTypeInterpretation.

@Test
@FailureExpected(jiraKey = "HHH-9089")
public void testEnumTypeInterpretation() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Customer.class).buildMetadata();
        PersistentClass classMetadata = metadata.getEntityBinding(Customer.class.getName());
        Property investmentsProperty = classMetadata.getProperty("investments");
        Collection investmentsValue = (Collection) investmentsProperty.getValue();
        Component investmentMetadata = (Component) investmentsValue.getElement();
        Value descriptionValue = investmentMetadata.getProperty("description").getValue();
        assertEquals(1, descriptionValue.getColumnSpan());
        Column selectable = (Column) descriptionValue.getColumnIterator().next();
        assertEquals((Long) 500L, selectable.getLength());
        Component amountMetadata = (Component) investmentMetadata.getProperty("amount").getValue();
        SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty("currency").getValue();
        CustomType<Object> currencyType = (CustomType<Object>) currencyMetadata.getType();
        int[] currencySqlTypes = currencyType.getSqlTypeCodes(metadata);
        assertEquals(1, currencySqlTypes.length);
        assertJdbcTypeCode(Types.VARCHAR, currencySqlTypes[0]);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : CustomType(org.hibernate.type.CustomType) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SimpleValue(org.hibernate.mapping.SimpleValue) Column(org.hibernate.mapping.Column) SimpleValue(org.hibernate.mapping.SimpleValue) Value(org.hibernate.mapping.Value) Collection(org.hibernate.mapping.Collection) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Example 13 with FailureExpected

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

the class EmbeddableWithOne2ManyTest method testBasicOps.

@Test
@FailureExpected(jiraKey = "HHH-4599")
public void testBasicOps(SessionFactoryScope scope) {
    Person person = new Person("John", "Dillinger");
    scope.inTransaction(session -> {
        Alias alias = new Alias("Public Enemy", "Number 1", "FBI");
        session.persist(alias);
        person.getName().getAliases().add(alias);
        session.persist(person);
    });
    scope.inTransaction(session -> {
        Person p = (Person) session.load(Person.class, person.getId());
        session.delete(p);
        List aliases = session.createQuery("from Alias").list();
        assertEquals(0, aliases.size());
    });
}
Also used : List(java.util.List) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Example 14 with FailureExpected

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

the class UnidirectionalOneToManyUniqueConstraintOrderColumnTest method testRemovingOneAndAddingTwoElements.

@Test
@FailureExpected(jiraKey = "HHH-1268")
public void testRemovingOneAndAddingTwoElements(EntityManagerFactoryScope scope) {
    scope.inTransaction(entityManager -> {
        ParentData parent = entityManager.find(ParentData.class, 1L);
        List<ChildData> children = parent.getChildren();
        children.remove(0);
        children.add(1, new ChildData("Another"));
        children.add(new ChildData("Another Another"));
    });
    scope.inEntityManager(entityManager -> {
        ParentData parent = entityManager.find(ParentData.class, 1L);
        List<String> childIds = parent.getChildren().stream().map(ChildData::toString).collect(Collectors.toList());
        int i = 0;
        assertEquals("Two", childIds.get(i++));
        assertEquals("Another", childIds.get(i++));
        assertEquals("Three", childIds.get(i++));
        assertEquals("Another Another", childIds.get(i));
    });
}
Also used : UniqueConstraint(jakarta.persistence.UniqueConstraint) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Example 15 with FailureExpected

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

the class UnidirectionalOneToManyUniqueConstraintOrderColumnTest method testRemovingAndAddingAnElement.

@Test
@FailureExpected(jiraKey = "HHH-1268")
public void testRemovingAndAddingAnElement(EntityManagerFactoryScope scope) {
    scope.inTransaction(entityManager -> {
        ParentData parent = entityManager.find(ParentData.class, 1L);
        List<ChildData> children = parent.getChildren();
        children.remove(0);
        children.add(1, new ChildData("Another"));
    });
    scope.inEntityManager(entityManager -> {
        ParentData parent = entityManager.find(ParentData.class, 1L);
        List<String> childIds = parent.getChildren().stream().map(ChildData::toString).collect(Collectors.toList());
        int i = 0;
        assertEquals("Two", childIds.get(i++));
        assertEquals("Another", childIds.get(i++));
        assertEquals("Three", childIds.get(i));
    });
}
Also used : UniqueConstraint(jakarta.persistence.UniqueConstraint) 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