本文整理汇总了Java中org.hibernate.ObjectNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java ObjectNotFoundException类的具体用法?Java ObjectNotFoundException怎么用?Java ObjectNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectNotFoundException类属于org.hibernate包,在下文中一共展示了ObjectNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
@Override
public final Object load() {
final Serializable entityId = resolveNaturalId( this.naturalIdParameters );
if ( entityId == null ) {
return null;
}
try {
return this.getIdentifierLoadAccess().load( entityId );
}
catch (EntityNotFoundException enf) {
// OK
}
catch (ObjectNotFoundException nf) {
// OK
}
return null;
}
示例2: getAssignment
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
public Assignment getAssignment(Class_ clazz) {
Long solutionId = getSolutionId(clazz);
if (solutionId==null) return super.getAssignment(clazz);
Iterator i = null;
try {
i = clazz.getAssignments().iterator();
} catch (ObjectNotFoundException e) {
new _RootDAO().getSession().refresh(clazz);
i = clazz.getAssignments().iterator();
}
while (i.hasNext()) {
Assignment a = (Assignment)i.next();
if (solutionId.equals(a.getSolution().getUniqueId())) return a;
}
return null;
}
示例3: testLoadWithNotFound
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
@Test
public void testLoadWithNotFound() throws HibernateException {
ObjectNotFoundException onfex = new ObjectNotFoundException("id", TestBean.class.getName());
given(session.load(TestBean.class, "id")).willThrow(onfex);
try {
hibernateTemplate.load(TestBean.class, "id");
fail("Should have thrown HibernateObjectRetrievalFailureException");
}
catch (HibernateObjectRetrievalFailureException ex) {
// expected
assertEquals(TestBean.class.getName(), ex.getPersistentClassName());
assertEquals("id", ex.getIdentifier());
assertEquals(onfex, ex.getCause());
}
verify(session).close();
}
示例4: findOrCreateMessage
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
/**
* Find or create message.
*
* @param aMessage
* the a message
* @param session
* the session
* @return the message
*/
private synchronized Message findOrCreateMessage(final Message aMessage,
final Session session) {
Message message = null;
try {
message = this.findMessage(aMessage, session);
if (null == message) {
session.saveOrUpdate(aMessage.getPoster());
message = aMessage;
session.saveOrUpdate(aMessage);
// messagesCache.put(key, message);
}
}
catch (final ObjectNotFoundException e) {
HibernateHelper.logger.warn(message.getPoster(), e);
}
return message;
}
示例5: onSubmit_shouldPurgeTheProvider
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
/**
* @verifies should purge the provider
* @see org.openmrs.web.controller.provider.ProviderFormController#onSubmit(javax.servlet.http.HttpServletRequest,
* String, String, String, String, org.openmrs.Provider,
* org.springframework.validation.BindingResult, org.springframework.ui.ModelMap)
*/
@Test(expected = ObjectNotFoundException.class)
public void onSubmit_shouldPurgeTheProvider() throws Exception {
executeDataSet(PROVIDERS_ATTRIBUTES_XML);
executeDataSet(PROVIDERS_XML);
Provider provider = Context.getProviderService().getProvider(2);
ProviderAttributeType providerAttributeType = Context.getProviderService().getProviderAttributeType(1);
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
BindException errors = new BindException(provider, "provider");
ProviderFormController providerFormController = (ProviderFormController) applicationContext
.getBean("providerFormController");
providerFormController.onSubmit(mockHttpServletRequest, null, null, null, "purge", provider, errors,
createModelMap(providerAttributeType));
Context.flushSession();
Assert.assertNull(Context.getProviderService().getProvider(2));
}
示例6: removeTransientEntries
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
public void removeTransientEntries(Map<Long, String> transientMap) {
CalendarEntry entry;
Transaction tx = _persister.getOrBeginTransaction();
for (Long entryID : transientMap.keySet()) {
String status = transientMap.get(entryID);
if (status.equals(TRANSIENT_FLAG)) {
try {
entry = (CalendarEntry) _persister.load(CalendarEntry.class, entryID);
_persister.delete(entry, tx);
}
catch (ObjectNotFoundException onfe) {
// nothing to remove if not found
}
}
else {
entry = (CalendarEntry) _persister.get(CalendarEntry.class, entryID);
if (entry != null) {
entry.setStatus(status);
_persister.update(entry, tx);
}
}
}
}
示例7: canManipulateReport
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
private boolean canManipulateReport(PostReport report) {
int[] forumIds = this.userSession.getRoleManager()
.getRoleValues(SecurityConstants.FORUM);
for (int forumId : forumIds) {
// Make sure the user is removing a report from a forum he can
// moderate
try {
if (forumId == report.getPost().getForum().getId()) {
return true;
}
} catch (ObjectNotFoundException e) {
return true;
}
}
return false;
}
示例8: handleLastPostDeleted
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
private void handleLastPostDeleted(Post post) {
boolean isLastPost = false;
try {
// FIXME: post.getTopic.getLastPost() may throw this exception,
// because the post itself was deleted before this method,
// and a call to post.getTopic().getLastPost() may issue
// a query to load the last post of such topic, which
// won't exist, of course. So, is this expected, or should
// we handle this using another approach?
isLastPost = post.getTopic().getLastPost().equals(post);
}
catch (ObjectNotFoundException e) {
isLastPost = true;
}
if (isLastPost) {
post.getTopic().setLastPost(this.topicRepository.getLastPost(post.getTopic()));
}
}
示例9: handleFirstPostDeleted
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
private boolean handleFirstPostDeleted(Post post) {
boolean isFirstPost = false;
try {
isFirstPost = post.getTopic().getFirstPost().equals(post);
}
catch (ObjectNotFoundException e) {
isFirstPost = true;
}
if (isFirstPost) {
Post firstPost = this.topicRepository.getFirstPost(post.getTopic());
post.getTopic().setFirstPost(firstPost);
post.getTopic().setUser(firstPost.getUser());
return true;
}
return false;
}
示例10: deleted
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
/**
* The actions are:
* <ul>
* <li> If last post, update forum.lastPost
* </ul>
*/
@Override
public void deleted(Post post) {
boolean isLastPost = false;
try {
// FIXME: Check TopicPostEvent#handleLastPostDeleted
isLastPost = post.equals(post.getForum().getLastPost());
}
catch (ObjectNotFoundException e) {
isLastPost = true;
}
if (isLastPost) {
Post lastPost = this.repository.getLastPost(post.getForum());
post.getForum().setLastPost(lastPost);
}
}
示例11: deleted
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
/**
* The actions are:
* <ul>
* <li> If topic.lastPost == forum.lastPost, update forum.lastPost
* </ul>
*/
@Override
public void deleted(Topic topic) {
Forum forum = topic.getForum();
boolean topicMatches = false;
try {
// FIXME: Check TopiPostEvent#handleLastPostDeleted
topicMatches = forum.getLastPost() == null
? true
: forum.getLastPost().getTopic().equals(topic);
}
catch (ObjectNotFoundException e) {
topicMatches = true;
}
if (topicMatches) {
forum.setLastPost(this.repository.getLastPost(forum));
}
}
示例12: removeItem
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
public void removeItem(Item item) {
try {
if (item == null) {
throw new IllegalArgumentException("item cannot be null");
}
if (item instanceof HomeCollectionItem) {
throw new IllegalArgumentException("cannot remove root item");
}
removeItemInternal(item);
getSession().flush();
} catch (ObjectNotFoundException onfe) {
throw new ItemNotFoundException("item not found");
} catch (ObjectDeletedException ode) {
throw new ItemNotFoundException("item not found");
} catch (UnresolvableObjectException uoe) {
throw new ItemNotFoundException("item not found");
} catch (HibernateException e) {
getSession().clear();
throw SessionFactoryUtils.convertHibernateAccessException(e);
}
}
示例13: getAuthor
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
public String getAuthor() {
try {
// try to handle as identity id
final Identity identity = getBaseSecurity().loadIdentityByKey(Long.valueOf(author));
if (identity == null) {
return author;
}
return identity.getName();
} catch (final NumberFormatException nEx) {
return author;
} catch (final ObjectNotFoundException oEx) {
DBFactory.getInstanceForClosing().rollbackAndCloseSession();
return author;
} catch (final Throwable th) {
DBFactory.getInstanceForClosing().rollbackAndCloseSession();
return author;
}
}
示例14: lookupConfigFileByChannelAndName
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
/**
* Lookup a ConfigFile by its channel's id and config file name's id
* @param channel The file's config channel id
* @param name The file's config file name id
* @return the ConfigFile found or null if not found.
*/
public static ConfigFile lookupConfigFileByChannelAndName(Long channel, Long name) {
Session session = HibernateFactory.getSession();
Query query =
session.getNamedQuery("ConfigFile.findByChannelAndName")
.setLong("channel_id", channel.longValue())
.setLong("name_id", name.longValue())
.setLong("state_id", ConfigFileState.normal().
getId().longValue())
//Retrieve from cache if there
.setCacheable(true);
try {
return (ConfigFile) query.uniqueResult();
}
catch (ObjectNotFoundException e) {
return null;
}
}
示例15: getActionChain
import org.hibernate.ObjectNotFoundException; //导入依赖的package包/类
/**
* Gets an Action Chain by id.
* @param requestor the user whose chain we're looking for
* @param id the id
* @return the Action Chain
* @throws ObjectNotFoundException if there is no such id accessible to the requestor
*/
public static ActionChain getActionChain(User requestor, Long id)
throws ObjectNotFoundException {
log.debug("Looking up Action Chain with id " + id);
if (id == null) {
return null;
}
ActionChain ac = (ActionChain) getSession()
.createCriteria(ActionChain.class)
.add(Restrictions.eq("id", id))
.add(Restrictions.eq("user", requestor))
.uniqueResult();
if (ac == null) {
throw new ObjectNotFoundException(ActionChain.class,
"ActionChain Id " + id + " not found for User " +
requestor.getLogin());
}
return ac;
}