use of org.hibernate.ObjectNotFoundException in project opennms by OpenNMS.
the class AcknowledgmentDaoHibernate method findAcknowledgables.
/** {@inheritDoc} */
@Override
public List<Acknowledgeable> findAcknowledgables(final OnmsAcknowledgment ack) {
List<Acknowledgeable> ackables = new ArrayList<Acknowledgeable>();
if (ack == null || ack.getAckType() == null) {
return ackables;
}
if (ack.getAckType().equals(AckType.ALARM)) {
final OnmsAlarm alarm = findAlarm(ack);
try {
if (alarm != null && alarm.getAckId() != null) {
ackables.add(alarm);
List<OnmsNotification> notifs = findRelatedNotifications(alarm);
if (notifs != null) {
for (OnmsNotification notif : notifs) {
try {
if (notif.getAckId() != null) {
ackables.add(notif);
}
} catch (final ObjectNotFoundException e) {
LOG.warn("found ackables for alarm #{} but ackable was invalid", ack.getRefId(), e);
}
}
}
}
} catch (final ObjectNotFoundException e) {
LOG.warn("unable to find alarm with ID {}", ack.getRefId(), e);
}
} else if (ack.getAckType().equals(AckType.NOTIFICATION)) {
final OnmsNotification notif = findNotification(ack);
try {
if (notif != null && notif.getAckId() != null) {
ackables.add(notif);
try {
if (notif.getEvent() != null) {
final OnmsAlarm alarm = notif.getEvent().getAlarm();
if (alarm != null) {
ackables.add(alarm);
}
}
} catch (final ObjectNotFoundException e) {
LOG.warn("unable to find alarm for notification #{}", notif.getNotifyId(), e);
}
}
} catch (final ObjectNotFoundException e) {
LOG.warn("unable to find notification with ID {}", ack.getRefId(), e);
}
}
return ackables;
}
use of org.hibernate.ObjectNotFoundException in project hibernate-orm by hibernate.
the class MasterDetailTest method testCustomPersister.
@Test
public void testCustomPersister() throws Exception {
Session s = openSession();
Custom c = new Custom();
c.setName("foo");
c.id = "100";
s.beginTransaction();
String id = id = (String) s.save(c);
assertTrue(c == s.load(Custom.class, id));
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
c = (Custom) s.load(Custom.class, id);
assertTrue(c.getName().equals("foo"));
c.setName("bar");
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
c = (Custom) s.load(Custom.class, id);
assertTrue(c.getName().equals("bar"));
s.delete(c);
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
boolean none = false;
try {
s.load(Custom.class, id);
} catch (ObjectNotFoundException onfe) {
none = true;
}
assertTrue(none);
s.close();
}
use of org.hibernate.ObjectNotFoundException in project hibernate-orm by hibernate.
the class FooBarTest method testLoadAfterDelete.
@Test
public void testLoadAfterDelete() throws Exception {
Session s = openSession();
s.beginTransaction();
Foo foo = new Foo();
Serializable id = s.save(foo);
s.flush();
s.delete(foo);
boolean err = false;
try {
s.load(Foo.class, id);
} catch (ObjectNotFoundException ode) {
err = true;
}
assertTrue(err);
s.flush();
err = false;
try {
((FooProxy) s.load(Foo.class, id)).getBool();
} catch (ObjectNotFoundException onfe) {
err = true;
}
assertTrue(err);
//yuck!!
id = FumTest.fumKey("abc");
Fo fo = Fo.newFo((FumCompositeID) id);
s.save(fo);
s.flush();
s.delete(fo);
err = false;
try {
s.load(Fo.class, id);
} catch (ObjectNotFoundException ode) {
err = true;
}
assertTrue(err);
s.flush();
err = false;
try {
s.load(Fo.class, id);
} catch (ObjectNotFoundException onfe) {
err = true;
}
assertTrue(err);
s.getTransaction().commit();
s.close();
}
use of org.hibernate.ObjectNotFoundException in project hibernate-orm by hibernate.
the class ProxyTest method testSubsequentNonExistentProxyAccess.
@Test
public void testSubsequentNonExistentProxyAccess() {
Session s = openSession();
Transaction t = s.beginTransaction();
DataPoint proxy = (DataPoint) s.load(DataPoint.class, new Long(-1));
assertFalse(Hibernate.isInitialized(proxy));
try {
proxy.getDescription();
fail("proxy access did not fail on non-existent proxy");
} catch (ObjectNotFoundException onfe) {
// expected
} catch (Throwable e) {
fail("unexpected exception type on non-existent proxy access : " + e);
}
// try it a second (subsequent) time...
try {
proxy.getDescription();
fail("proxy access did not fail on non-existent proxy");
} catch (ObjectNotFoundException onfe) {
// expected
} catch (Throwable e) {
fail("unexpected exception type on non-existent proxy access : " + e);
}
t.commit();
s.close();
}
use of org.hibernate.ObjectNotFoundException in project hibernate-orm by hibernate.
the class CollectionCacheEvictionTest method testCollectionCacheEvictionRemove.
@Test
public void testCollectionCacheEvictionRemove() {
Session s = openSession();
s.beginTransaction();
Company company = (Company) s.get(Company.class, 1);
// init cache of collection
assertEquals(1, company.getUsers().size());
s.delete(company.getUsers().get(0));
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
company = (Company) s.get(Company.class, 1);
// fails if cache is not evicted
try {
assertEquals(0, company.getUsers().size());
} catch (ObjectNotFoundException e) {
fail("Cached element not found");
}
s.close();
}
Aggregations