/**
* Contains the logic to query for an already persisted EventType with the same type value.
*/
protected EventType findExistingEventType(EventType eventType) {
if (eventType.getId() != 0) {
final EventType foundEventType = this.entityManager.find(EventType.class, eventType.getId());
if (foundEventType != null) {
return foundEventType;
}
eventType.setId(0);
}
//No id, do a lookup based on the event type
final HibernateEntityManager hibernateEntityManager = ((HibernateEntityManager)this.entityManager);
final Session session = hibernateEntityManager.getSession();
//Setup the Criteria query
final Criteria eventTypeCriteria = session.createCriteria(EventType.class);
eventTypeCriteria.add(Restrictions.naturalId().set("type", eventType.getType()));
eventTypeCriteria.setCacheable(true);
eventTypeCriteria.setMaxResults(1);
final EventType foundEventType = (EventType)eventTypeCriteria.uniqueResult();
return foundEventType;
}