Search in sources :

Example 61 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class DeleteOneToManyOrphansTest method testOrphanedWhileManagedMergeOwner.

@Test
@TestForIssue(jiraKey = "HHH-9568")
@FailureExpected(jiraKey = "HHH-9568")
public void testOrphanedWhileManagedMergeOwner() {
    createData();
    EntityManager entityManager = getOrCreateEntityManager();
    entityManager.getTransaction().begin();
    List results = entityManager.createQuery("from Feature").getResultList();
    assertEquals(1, results.size());
    results = entityManager.createQuery("from Product").getResultList();
    assertEquals(1, results.size());
    Product product = (Product) results.get(0);
    assertEquals(1, product.getFeatures().size());
    product.getFeatures().clear();
    entityManager.merge(product);
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManager = getOrCreateEntityManager();
    entityManager.getTransaction().begin();
    product = entityManager.find(Product.class, product.getId());
    assertEquals(0, product.getFeatures().size());
    results = entityManager.createQuery("from Feature").getResultList();
    assertEquals(0, results.size());
    results = entityManager.createQuery("from Product").getResultList();
    assertEquals(1, results.size());
    entityManager.getTransaction().commit();
    entityManager.close();
    cleanupData();
}
Also used : EntityManager(javax.persistence.EntityManager) List(java.util.List) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 62 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class EmbeddedTypeTest method testSingularAttributeAccessByName.

@Test
@TestForIssue(jiraKey = "HHH-4702")
public void testSingularAttributeAccessByName() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    SingularAttribute soldDate_ = em.getMetamodel().embeddable(ShelfLife.class).getSingularAttribute("soldDate");
    assertEquals(java.sql.Date.class, soldDate_.getBindableJavaType());
    assertEquals(java.sql.Date.class, soldDate_.getType().getJavaType());
    assertEquals(java.sql.Date.class, soldDate_.getJavaType());
    em.getTransaction().commit();
    em.close();
}
Also used : SingularAttribute(javax.persistence.metamodel.SingularAttribute) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 63 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class QueryWithLiteralsInSelectExpressionTest method testSelectNullLiterals.

@Test
@TestForIssue(jiraKey = "HHH-10230")
public void testSelectNullLiterals() {
    final EntityManager entityManager = getOrCreateEntityManager();
    try {
        final List<Object[]> elements = entityManager.createQuery("SELECT cast(null as boolean), false, e.name FROM MyEntity e", Object[].class).getResultList();
        Assert.assertEquals(1, elements.size());
        Assert.assertEquals(3, elements.get(0).length);
        Assert.assertEquals(null, elements.get(0)[0]);
        Assert.assertEquals(false, elements.get(0)[1]);
        Assert.assertEquals("Fab", elements.get(0)[2]);
    } finally {
        entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 64 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class HSQLStoreProcedureTest method testGetPositionalParameters.

@Test
@TestForIssue(jiraKey = "HHH-10915")
public void testGetPositionalParameters() {
    EntityManager em = entityManagerFactory.createEntityManager();
    try {
        StoredProcedureQuery query = em.createNamedStoredProcedureQuery("User.inoutproc");
        final Set<Parameter<?>> parameters = query.getParameters();
        assertThat(parameters.size(), is(2));
        try {
            query.getParameter(1);
            fail("An IllegalArgumentException is expected, The stored procedure has named parameters not positional");
        } catch (IllegalArgumentException iae) {
        //expected
        }
        try {
            query.getParameter(1, String.class);
            fail("An IllegalArgumentException is expected, The stored procedure has named parameters not positional");
        } catch (IllegalArgumentException iae) {
        //expected
        }
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(javax.persistence.NamedStoredProcedureQuery) StoredProcedureParameter(javax.persistence.StoredProcedureParameter) Parameter(javax.persistence.Parameter) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 65 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class HSQLStoreProcedureTest method testNamedStoredProcedureExecution.

@Test
@TestForIssue(jiraKey = "HHH-10515")
public void testNamedStoredProcedureExecution() {
    EntityManager em = entityManagerFactory.createEntityManager();
    try {
        StoredProcedureQuery query = em.createNamedStoredProcedureQuery("User.inoutproc");
        query.setParameter("arg1", 1);
        query.execute();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(javax.persistence.NamedStoredProcedureQuery) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

TestForIssue (org.hibernate.testing.TestForIssue)649 Test (org.junit.Test)647 Session (org.hibernate.Session)357 EntityManager (javax.persistence.EntityManager)97 List (java.util.List)91 Transaction (org.hibernate.Transaction)88 MetadataSources (org.hibernate.boot.MetadataSources)47 ArrayList (java.util.ArrayList)38 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)38 Query (org.hibernate.Query)28 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)25 Metadata (org.hibernate.boot.Metadata)24 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)24 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)23 Map (java.util.Map)22 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)19 HashMap (java.util.HashMap)18 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)18 PersistentClass (org.hibernate.mapping.PersistentClass)18 HibernateException (org.hibernate.HibernateException)16