use of org.hibernate.testing.logger.Triggerable in project hibernate-orm by hibernate.
the class OrmVersion1SupportedTest method testOrm1Support.
@Test
public void testOrm1Support() {
Triggerable triggerable = logInspection.watchForLogMessages("HHH00196");
Session s = openSession();
Transaction tx = s.beginTransaction();
Light light = new Light();
light.name = "the light at the end of the tunnel";
s.persist(light);
s.flush();
s.clear();
assertEquals(1, s.getNamedQuery("find.the.light").list().size());
tx.rollback();
s.close();
assertFalse(triggerable.wasTriggered());
}
use of org.hibernate.testing.logger.Triggerable in project hibernate-orm by hibernate.
the class NonRootEntityWithCacheAnnotationTest method testCacheOnNonRootEntity.
@Test
public void testCacheOnNonRootEntity() {
Map settings = new HashMap();
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE);
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
Triggerable triggerable = logInspection.watchForLogMessages("HHH000482");
Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(ABase.class).addAnnotatedClass(AEntity.class).buildMetadata();
assertTrue(triggerable.wasTriggered());
assertNull((metadata.getEntityBinding(AEntity.class.getName())).getCacheConcurrencyStrategy());
serviceRegistry.destroy();
}
use of org.hibernate.testing.logger.Triggerable in project hibernate-orm by hibernate.
the class NonRootEntityWithCacheableAnnotationTest method testCacheableOnNonRootEntity.
@Test
public void testCacheableOnNonRootEntity() {
Map settings = new HashMap();
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-write");
settings.put(AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE);
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
Triggerable triggerable = logInspection.watchForLogMessages("HHH000482");
Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(ABase.class).addAnnotatedClass(AEntity.class).buildMetadata();
assertTrue(triggerable.wasTriggered());
assertNull((metadata.getEntityBinding(AEntity.class.getName())).getCacheConcurrencyStrategy());
serviceRegistry.destroy();
}
use of org.hibernate.testing.logger.Triggerable in project hibernate-orm by hibernate.
the class AnnotationBinderTest method testInvalidPrimaryKeyJoinColumnAnnotationMessageContainsClassName.
@Test
public void testInvalidPrimaryKeyJoinColumnAnnotationMessageContainsClassName() throws Exception {
Triggerable triggerable = logInspection.watchForLogMessages("HHH000137");
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder();
Metadata metadata = new MetadataSources(srb.build()).addAnnotatedClass(InvalidPrimaryKeyJoinColumnAnnotationEntity.class).buildMetadata();
assertTrue("Expected warning HHH00137 but it wasn't triggered", triggerable.wasTriggered());
assertTrue("Expected invalid class name in warning HHH00137 message but it does not apper to be present; got " + triggerable.triggerMessage(), triggerable.triggerMessage().matches(".*\\b\\Q" + InvalidPrimaryKeyJoinColumnAnnotationEntity.class.getName() + "\\E\\b.*"));
}
use of org.hibernate.testing.logger.Triggerable in project hibernate-orm by hibernate.
the class MultipleSessionCollectionWarningTest method testSetCurrentSessionOverwritesNonConnectedSesssion.
@Test
@TestForIssue(jiraKey = "HHH-9518")
public void testSetCurrentSessionOverwritesNonConnectedSesssion() {
Parent p = new Parent();
Child c = new Child();
p.children.add(c);
Session s1 = openSession();
s1.getTransaction().begin();
s1.saveOrUpdate(p);
// Now remove the collection from the PersistenceContext without unsetting its session
// This should never be done in practice; it is done here only to test that the warning
// gets logged. s1 will not function properly so the transaction will ultimately need
// to be rolled-back.
CollectionEntry ce = (CollectionEntry) ((SessionImplementor) s1).getPersistenceContext().getCollectionEntries().remove(p.children);
assertNotNull(ce);
// the collection session should still be s1; the collection is no longer "connected" because its
// CollectionEntry has been removed.
assertSame(s1, ((AbstractPersistentCollection) p.children).getSession());
Session s2 = openSession();
s2.getTransaction().begin();
Triggerable triggerable = logInspection.watchForLogMessages("HHH000470:");
assertFalse(triggerable.wasTriggered());
// The following should trigger warning because we're setting a new session when the collection already
// has a non-null session (and the collection is not "connected" to that session);
// Since s1 was not flushed, the collection role will not be known (no way to test that other than inspection).
s2.saveOrUpdate(p);
assertTrue(triggerable.wasTriggered());
// collection's session should be overwritten with s2
assertSame(s2, ((AbstractPersistentCollection) p.children).getSession());
s2.getTransaction().rollback();
s2.close();
s1.getTransaction().rollback();
s1.close();
}
Aggregations