use of org.hibernate.ObjectNotFoundException in project hibernate-orm by hibernate.
the class CollectionCacheEvictionTest method testCollectionCacheEvictionRemoveWithEntityOutOfContext.
@Test
public void testCollectionCacheEvictionRemoveWithEntityOutOfContext() {
Session s = openSession();
Company company = s.get(Company.class, 1);
assertEquals(1, company.getUsers().size());
s.close();
s = openSession();
s.beginTransaction();
s.delete(company.getUsers().get(0));
s.getTransaction().commit();
s.close();
s = openSession();
company = s.get(Company.class, 1);
try {
assertEquals(0, company.getUsers().size());
} catch (ObjectNotFoundException e) {
fail("Cached element not found");
}
s.close();
}
use of org.hibernate.ObjectNotFoundException in project hibernate-orm by hibernate.
the class CollectionCacheEvictionTest method testCollectionCacheEvictionUpdateWithEntityOutOfContext.
@Test
public void testCollectionCacheEvictionUpdateWithEntityOutOfContext() {
Session s = openSession();
Company company1 = s.get(Company.class, 1);
Company company2 = s.get(Company.class, 2);
assertEquals(1, company1.getUsers().size());
assertEquals(0, company2.getUsers().size());
s.close();
s = openSession();
s.beginTransaction();
User user = s.get(User.class, 1);
user.setCompany(company2);
s.getTransaction().commit();
s.close();
s = openSession();
company1 = s.get(Company.class, 1);
company2 = s.get(Company.class, 2);
assertEquals(1, company2.getUsers().size());
try {
assertEquals(0, company1.getUsers().size());
} catch (ObjectNotFoundException e) {
fail("Cached element not found");
}
s.close();
}
use of org.hibernate.ObjectNotFoundException in project hibernate-orm by hibernate.
the class CollectionCacheEvictionTest method testCollectionCacheEvictionUpdate.
@Test
public void testCollectionCacheEvictionUpdate() {
Session s = openSession();
s.beginTransaction();
Company company1 = (Company) s.get(Company.class, 1);
Company company2 = (Company) s.get(Company.class, 2);
// init cache of collection
assertEquals(1, company1.getUsers().size());
assertEquals(0, company2.getUsers().size());
User user = (User) s.get(User.class, 1);
user.setCompany(company2);
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
company1 = (Company) s.get(Company.class, 1);
company2 = (Company) s.get(Company.class, 2);
assertEquals(1, company2.getUsers().size());
// fails if cache is not evicted
try {
assertEquals(0, company1.getUsers().size());
} catch (ObjectNotFoundException e) {
fail("Cached element not found");
}
s.close();
}
use of org.hibernate.ObjectNotFoundException in project hibernate-orm by hibernate.
the class ParentChildTest method testLoadAfterNonExists.
@Test
public void testLoadAfterNonExists() throws HibernateException, SQLException {
Session session = openSession();
if ((getDialect() instanceof MySQLDialect) || (getDialect() instanceof IngresDialect)) {
session.doWork(new AbstractWork() {
@Override
public void execute(Connection connection) throws SQLException {
connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
}
});
}
session.getTransaction().begin();
// First, prime the fixture session to think the entity does not exist
try {
session.load(Simple.class, new Long(-1));
fail();
} catch (ObjectNotFoundException onfe) {
if (getDialect() instanceof TeradataDialect) {
session.getTransaction().rollback();
session.getTransaction().begin();
}
// this is correct
}
// Next, lets create that entity "under the covers"
Session anotherSession = sessionFactory().openSession();
anotherSession.beginTransaction();
Simple myNewSimple = new Simple(Long.valueOf(-1));
myNewSimple.setName("My under the radar Simple entity");
myNewSimple.setAddress("SessionCacheTest.testLoadAfterNonExists");
myNewSimple.setCount(1);
myNewSimple.setDate(new Date());
myNewSimple.setPay(Float.valueOf(100000000));
anotherSession.save(myNewSimple);
anotherSession.getTransaction().commit();
anotherSession.close();
// Now, lets make sure the original session can see the created row...
session.clear();
try {
Simple dummy = (Simple) session.get(Simple.class, Long.valueOf(-1));
assertNotNull("Unable to locate entity Simple with id = -1", dummy);
session.delete(dummy);
} catch (ObjectNotFoundException onfe) {
fail("Unable to locate entity Simple with id = -1");
}
session.getTransaction().commit();
session.close();
}
use of org.hibernate.ObjectNotFoundException in project opennms by OpenNMS.
the class InsSession method getXMLEvent.
private Event getXMLEvent(final OnmsEvent ev) {
final Integer id = ev.getId();
LOG.info("Working on XML Event for id: {}", id);
LOG.debug("Setting Event id: {}", id);
final Event e = new Event();
e.setDbid(id);
//UEI
final String uei = ev.getEventUei();
if (uei != null) {
LOG.debug("Setting Event uei: {}", uei);
e.setUei(uei);
} else {
LOG.warn("No Event uei found: skipping event....");
return null;
}
// Source
final String source = ev.getEventSource();
if (source != null) {
LOG.debug("Setting Event source: {}", source);
e.setSource(source);
} else {
LOG.info("No Event source found.");
}
//nodeid
final Integer nodeid = ev.getNode().getId();
if (ev.getNode() != null && nodeid != null) {
LOG.debug("Setting Event nodeid: {}", nodeid);
e.setNodeid(nodeid.longValue());
} else {
LOG.info("No Event node found.");
}
// timestamp
final Date time = ev.getEventTime();
if (time != null) {
LOG.debug("Setting event date timestamp to (GMT): {}", time);
e.setTime(time);
} else {
LOG.info("No Event time found.");
}
// host
final String host = ev.getEventHost();
if (host != null) {
LOG.debug("Setting Event Host: {}", host);
e.setHost(host);
} else {
LOG.info("No Event host found.");
}
// interface
final InetAddress ipAddr = ev.getIpAddr();
if (ipAddr != null) {
LOG.debug("Setting Event Interface/ipaddress: {}", ipAddr);
e.setInterfaceAddress(ipAddr);
} else {
LOG.info("No Event ip address found.");
}
// Service Name
if (ev.getServiceType() != null) {
final String serviceName = ev.getServiceType().getName();
LOG.debug("Setting Event Service Name: {}", serviceName);
e.setService(serviceName);
} else {
LOG.info("No Event service name found.");
}
// Description
final String descr = ev.getEventDescr();
if (descr != null) {
LOG.debug("Setting Event Description: {}", descr);
e.setDescr(descr);
} else {
LOG.info("No Event ip address found.");
}
// Log message
final String logmsg = ev.getEventLogMsg();
if (logmsg != null) {
final Logmsg msg = new Logmsg();
LOG.debug("Setting Event Log Message: {}", logmsg);
msg.setContent(logmsg);
e.setLogmsg(msg);
} else {
LOG.info("No Event log Message found.");
}
// severity
final Integer severity = ev.getEventSeverity();
if (severity != null) {
LOG.debug("Setting Event Severity: {}", severity);
e.setSeverity(OnmsSeverity.get(severity).getLabel());
} else {
LOG.info("No Event severity found.");
}
final Integer ifIndex = ev.getIfIndex();
if (ifIndex != null && ifIndex > 0) {
e.setIfIndex(ifIndex);
e.setIfAlias(getIfAlias(nodeid, ifIndex));
} else {
e.setIfIndex(-1);
e.setIfAlias("-1");
}
// operator Instruction
final String operInstruct = ev.getEventOperInstruct();
if (operInstruct != null) {
LOG.debug("Setting Event Operator Instruction: {}", operInstruct);
e.setOperinstruct(operInstruct);
} else {
LOG.info("No Event operator Instruction found.");
}
// parms
final String eventParms = ev.getEventParms();
if (eventParms != null) {
LOG.debug("Setting Event Parms: {}", eventParms);
final List<Parm> parms = EventParameterUtils.decode(eventParms);
if (parms != null)
e.setParmCollection(parms);
} else {
LOG.info("No Event parms found.");
}
final AlarmData ad = new AlarmData();
final OnmsAlarm onmsAlarm = ev.getAlarm();
try {
if (onmsAlarm != null) {
ad.setReductionKey(onmsAlarm.getReductionKey());
ad.setAlarmType(onmsAlarm.getAlarmType());
ad.setClearKey(onmsAlarm.getClearKey());
e.setAlarmData(ad);
}
} catch (final ObjectNotFoundException e1) {
LOG.warn("Correlated alarm data not found.", e1);
}
LOG.info("Returning event with id: {}", id);
return e;
}
Aggregations