Search in sources :

Example 26 with TestForIssue

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

the class C3P0ConnectionProviderTest method testIsolationPropertyCouldBeEmpty.

@Test
@TestForIssue(jiraKey = "HHH-9498")
public void testIsolationPropertyCouldBeEmpty() {
    C3P0ConnectionProvider provider = new C3P0ConnectionProvider();
    try {
        Properties configuration = new Properties();
        configuration.setProperty(Environment.ISOLATION, "");
        provider.configure(configuration);
    } finally {
        provider.stop();
    }
}
Also used : C3P0ConnectionProvider(org.hibernate.c3p0.internal.C3P0ConnectionProvider) Properties(java.util.Properties) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 27 with TestForIssue

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

the class JdbcCompatibilityTest method testJdbc42.

@Test
@TestForIssue(jiraKey = "HHH-11308")
public void testJdbc42() {
    doInHibernate(this::sessionFactory, session -> {
        for (int i = 0; i < 5; i++) {
            IrrelevantEntity entity = new IrrelevantEntity();
            entity.setName(getClass().getName());
            session.persist(entity);
        }
        session.flush();
        session.doWork(connection -> {
            try (Statement statement = connection.createStatement()) {
                statement.executeUpdate("DELETE FROM IrrelevantEntity");
                assertEquals(5, statement.getLargeUpdateCount());
            }
        });
    });
}
Also used : Statement(java.sql.Statement) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 28 with TestForIssue

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

the class StatementCacheTest method testStatementCaching.

@Test
@TestForIssue(jiraKey = "HHH-7193")
public void testStatementCaching() {
    Session session = openSession();
    session.beginTransaction();
    //save 2 new entities, one valid, one invalid (neither should be persisted)
    IrrelevantEntity irrelevantEntity = new IrrelevantEntity();
    irrelevantEntity.setName("valid 1");
    session.save(irrelevantEntity);
    //name is required
    irrelevantEntity = new IrrelevantEntity();
    session.save(irrelevantEntity);
    try {
        session.flush();
        Assert.fail("Validation exception did not occur");
    } catch (Exception e) {
        //this is expected roll the transaction back
        session.getTransaction().rollback();
    }
    session.close();
    session = openSession();
    session.beginTransaction();
    //save a new entity and commit it
    irrelevantEntity = new IrrelevantEntity();
    irrelevantEntity.setName("valid 2");
    session.save(irrelevantEntity);
    session.flush();
    session.getTransaction().commit();
    session.close();
    //only one entity should have been inserted to the database (if the statement in the cache wasn't cleared then it would have inserted both entities)
    session = openSession();
    session.beginTransaction();
    Criteria criteria = session.createCriteria(IrrelevantEntity.class);
    List results = criteria.list();
    session.getTransaction().commit();
    session.close();
    Assert.assertEquals(1, results.size());
}
Also used : List(java.util.List) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 29 with TestForIssue

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

the class CollectionBinderTest method testAssociatedClassException.

@Test
@TestForIssue(jiraKey = "HHH-10106")
public void testAssociatedClassException() throws SQLException {
    final Collection collection = mock(Collection.class);
    final Map persistentClasses = mock(Map.class);
    final XClass collectionType = mock(XClass.class);
    final MetadataBuildingContext buildingContext = mock(MetadataBuildingContext.class);
    final InFlightMetadataCollector inFly = mock(InFlightMetadataCollector.class);
    final PersistentClass persistentClass = mock(PersistentClass.class);
    final Table table = mock(Table.class);
    when(buildingContext.getMetadataCollector()).thenReturn(inFly);
    when(persistentClasses.get(null)).thenReturn(null);
    when(collection.getOwner()).thenReturn(persistentClass);
    when(collectionType.getName()).thenReturn("List");
    when(persistentClass.getTable()).thenReturn(table);
    when(table.getName()).thenReturn("Hibernate");
    CollectionBinder collectionBinder = new CollectionBinder(false) {

        @Override
        protected Collection createCollection(PersistentClass persistentClass) {
            return null;
        }

        {
            final PropertyHolder propertyHolder = Mockito.mock(PropertyHolder.class);
            when(propertyHolder.getClassName()).thenReturn(CollectionBinderTest.class.getSimpleName());
            this.propertyName = "abc";
            this.propertyHolder = propertyHolder;
        }
    };
    String expectMessage = "Association [abc] for entity [CollectionBinderTest] references unmapped class [List]";
    try {
        collectionBinder.bindOneToManySecondPass(collection, persistentClasses, null, collectionType, false, false, buildingContext, null);
    } catch (MappingException e) {
        assertEquals(expectMessage, e.getMessage());
    }
}
Also used : InFlightMetadataCollector(org.hibernate.boot.spi.InFlightMetadataCollector) Table(org.hibernate.mapping.Table) PropertyHolder(org.hibernate.cfg.PropertyHolder) Collection(org.hibernate.mapping.Collection) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) Map(java.util.Map) XClass(org.hibernate.annotations.common.reflection.XClass) PersistentClass(org.hibernate.mapping.PersistentClass) MappingException(org.hibernate.MappingException) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 30 with TestForIssue

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

the class ConnectionCreatorTest method testBadUrl.

@Test
@TestForIssue(jiraKey = "HHH-8621")
public void testBadUrl() throws Exception {
    DriverConnectionCreator connectionCreator = new DriverConnectionCreator((Driver) Class.forName("org.h2.Driver").newInstance(), new StandardServiceRegistryImpl(true, new BootstrapServiceRegistryImpl(), Collections.<StandardServiceInitiator>emptyList(), Collections.<ProvidedService>emptyList(), Collections.emptyMap()) {

        @Override
        @SuppressWarnings("unchecked")
        public <R extends Service> R getService(Class<R> serviceRole) {
            if (JdbcServices.class.equals(serviceRole)) {
                // return a new, not fully initialized JdbcServicesImpl
                return (R) new JdbcServicesImpl();
            }
            return super.getService(serviceRole);
        }
    }, "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat", new Properties(), false, null);
    try {
        Connection conn = connectionCreator.createConnection();
        conn.close();
        fail("Expecting the bad Connection URL to cause an exception");
    } catch (JDBCConnectionException expected) {
    }
}
Also used : JdbcServicesImpl(org.hibernate.engine.jdbc.internal.JdbcServicesImpl) JDBCConnectionException(org.hibernate.exception.JDBCConnectionException) ProvidedService(org.hibernate.service.internal.ProvidedService) DriverConnectionCreator(org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator) StandardServiceInitiator(org.hibernate.boot.registry.StandardServiceInitiator) Connection(java.sql.Connection) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) Properties(java.util.Properties) BootstrapServiceRegistryImpl(org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) 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