本文整理汇总了Java中org.hibernate.NonUniqueResultException类的典型用法代码示例。如果您正苦于以下问题:Java NonUniqueResultException类的具体用法?Java NonUniqueResultException怎么用?Java NonUniqueResultException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NonUniqueResultException类属于org.hibernate包,在下文中一共展示了NonUniqueResultException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRoomByRoomNumber
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
@Override
public Room getRoomByRoomNumber(String roomNumber) {
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Room> query = session.createQuery("from Room where number=:roomNumber", Room.class);
query.setParameter("roomNumber", roomNumber);
logging.setMessage("RoomDaoImpl -> fetching room by number "+roomNumber);
return query.getSingleResult();
} catch (NonUniqueResultException e) {
logging.setMessage("RoomDaoImpl -> "+e.getLocalizedMessage());
final InformationFrame frame = new InformationFrame();
frame.setMessage("There is more than one room with this number!");
frame.setVisible(true);
}
session.close();
return null;
}
示例2: completeInfo
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
private void completeInfo(final PlayerDTO playerDTO) throws LogicException, ClientAuthException {
HibernateUtil.exec(new HibernateCallback<Void>() {
@Override
public Void run(Session session) throws LogicException, ClientAuthException {
try {
Player playerEnt = (Player) session.createQuery("from Player p where p.steamId = :sid")
.setLong("sid", playerDTO.getId()).uniqueResult();
if (playerEnt != null) {
playerDTO.setNick(playerEnt.getNick());
}
} catch (NonUniqueResultException e) {
throw LogicExceptionFormatted.format("Дубликация информации об игроке %d", playerDTO.getId());
}
return null;
}
});
}
示例3: getRoomByReservId
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
@Override
public Room getRoomByReservId(long id) {
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Room> query = session.createQuery("from Room where ReservationId=:id", Room.class);
query.setParameter("id", id);
logging.setMessage("RoomDaoImpl -> fetching room by identity :"+id);
return query.getSingleResult();
} catch (NonUniqueResultException e) {
session.getTransaction().rollback();
logging.setMessage("RoomDaoImpl -> "+e.getLocalizedMessage());
final InformationFrame frame = new InformationFrame();
frame.setMessage(e.getLocalizedMessage());
frame.setVisible(true);
}
session.close();
return null;
}
示例4: findByPuidDepartmentId
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
public static DepartmentalInstructor findByPuidDepartmentId(String puid, Long deptId, org.hibernate.Session hibSession) {
try {
return (DepartmentalInstructor)hibSession.
createQuery("select d from DepartmentalInstructor d where d.externalUniqueId=:puid and d.department.uniqueId=:deptId").
setString("puid", puid).
setLong("deptId",deptId.longValue()).
setCacheable(true).
setFlushMode(FlushMode.MANUAL).
uniqueResult();
} catch (NonUniqueResultException e) {
Debug.warning("There are two or more instructors with puid "+puid+" for department "+deptId+" -- returning the first one.");
return (DepartmentalInstructor)hibSession.
createQuery("select d from DepartmentalInstructor d where d.externalUniqueId=:puid and d.department.uniqueId=:deptId").
setString("puid", puid).
setLong("deptId",deptId.longValue()).
setCacheable(true).
setFlushMode(FlushMode.MANUAL).
list().get(0);
}
}
示例5: findByKey
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
/**
* Find by key.
*
* @param key
* the key
* @param session
* the session
* @param objclass
* the objclass
* @return the object
* @throws HibernateException
* the hibernate exception @+ aram objclass
*/
public Object findByKey(final String key, final Session session, final Class<?> objclass)
throws HibernateException {
final String queryText = objclass.getName() + ".findByKey";
final Query query = session.getNamedQuery(queryText);
query.setString("key", key);
Object uniqueResult = null;
try {
uniqueResult = query.uniqueResult();
}
catch (final NonUniqueResultException e) {
throw new RuntimeException(
"Got non-unique result for " + key + " on " + objclass.getName() + " " + e);
}
return uniqueResult;
}
示例6: changePasswordForUser
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
/**
*
* @param username Set the username
* @param newPassword Set the new password
*/
@Transactional(readOnly = false)
public final void changePasswordForUser(final String username,
final String newPassword) {
Assert.hasText(username);
Assert.hasText(newPassword);
try {
User user = dao.find(username);
if (user == null) {
throw new UsernameNotFoundException(username);
}
Object salt = this.saltSource.getSalt(user);
String password = passwordEncoder.encodePassword(newPassword, salt);
((User) user).setPassword(password);
dao.update((User) user);
userCache.removeUserFromCache(user.getUsername());
} catch (NonUniqueResultException nure) {
throw new IncorrectResultSizeDataAccessException(
"More than one user found with name '" + username + "'", 1);
}
}
示例7: loadUserByUsername
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
/**
* DO NOT CALL THIS METHOD IN LONG RUNNING SESSIONS OR CONVERSATIONS A
* THROWN UsernameNotFoundException WILL RENDER THE CONVERSATION UNUSABLE.
*
* @param username
* Set the username
* @return the userdetails of the user
*/
@Transactional(readOnly = true)
public final UserDetails loadUserByUsername(final String username) {
try {
Assert.hasText(username);
} catch (IllegalArgumentException iae) {
throw new UsernameNotFoundException(username, iae);
}
try {
User user = dao.load(username);
userCache.putUserInCache(user);
return user;
} catch (ObjectRetrievalFailureException orfe) {
throw new UsernameNotFoundException(username, orfe);
} catch (NonUniqueResultException nure) {
throw new IncorrectResultSizeDataAccessException(
"More than one user found with name '" + username + "'", 1);
}
}
示例8: getByExample
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
@Override
public T getByExample(EntityExample<T> example) {
Where<T> where = new Where<T>();
where.setExample(example);
ISearchParam isp = new SearchParam();
isp.setLimit(2);
isp.setOffset(0);
List<T> result = this.getAll(where, isp);
if (!ListHelper.hasElements(result)) {
return null;
}
if (result.size() == 1) {
return result.get(0);
}
throw new NonUniqueResultException(result.size());
}
示例9: courseNameExist
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
public boolean courseNameExist(Course course) {
boolean retorno = false;
try {
Criteria crit = getSession().createCriteria(getPersistentClass());
crit.add( eq("name", course.getName()).ignoreCase() );
Course c = (Course) crit.uniqueResult();
if(c != null && c.getId() != course.getId()) {
retorno = true;
}
} catch (NonUniqueResultException e) {
retorno = true;
}
return retorno;
}
示例10: getParentByChild
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
/**
* Retrieves parent node by child node id.
*
* @param childId
* @param depth
* negative values mean parent by Math.abs(depth) levels above,
* non-negative values mean absolute depth.
* @return parent node
* @throws LogicException
* @throws ClientAuthException
*/
@SuppressWarnings("unchecked")
public T getParentByChild(final Long childId, final Long depth) throws LogicException, ClientAuthException {
T childNode = (T) session.get(entityClass, childId);
Long parentDepth = null;
if (depth < 0) {
parentDepth = childNode.getDepth() + depth;
if (parentDepth < 0) {
throw new NestedSetManagerException(
"parentDepth < 0, childDepth = " + childNode.getDepth() + " requested depth = " + depth);
}
} else {
parentDepth = depth;
}
try {
return (T) session
.createQuery("from " + entityName + " node where node.leftnum <= :left and node.rightnum >= :right and depth = :depth")
.setLong("left", childNode.getLeftNum()).setLong("right", childNode.getRightNum()).setLong("depth", parentDepth)
.uniqueResult();
} catch (NonUniqueResultException e) {
throw new NestedSetManagerException("Non-unique parent: " + e.getMessage());
}
}
示例11: single
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
protected T single() {
try {
//noinspection unchecked
return (T) fullTextQuery.uniqueResult();
} catch (NonUniqueResultException ex) {
throw new IncorrectResultSizeDataAccessException(ex.getMessage(), 1);
} finally {
close();
}
}
示例12: uniqueElement
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
static Object uniqueElement(List list) throws NonUniqueResultException {
int size = list.size();
if (size==0) return null;
Object first = list.get(0);
for ( int i=1; i<size; i++ ) {
if ( list.get(i)!=first ) {
throw new NonUniqueResultException( list.size() );
}
}
return first;
}
示例13: handleFindTaskByUniqueName
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @see com.communote.server.persistence.tasks.TaskDao#findTaskByUniqueName()
*/
@Override
protected Task handleFindTaskByUniqueName(String uniqueName) {
List<?> result = getHibernateTemplate().find(QUERY_FIND_BY_UNIQUE_NAME, uniqueName);
if (result.size() > 1) {
throw new NonUniqueResultException(result.size());
}
return result.size() == 1 ? (Task) result.get(0) : null;
}
示例14: uniqueResult
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
private Object uniqueResult(org.hibernate.Query query) throws PageException {
try{
return query.uniqueResult();
}
catch(NonUniqueResultException e){
List list = query.list();
if(list.size()>0) return list.iterator().next();
throw CommonUtil.toPageException(e);
}
catch(Throwable t){
lucee.commons.lang.ExceptionUtil.rethrowIfNecessary(t);
throw CommonUtil.toPageException(t);
}
}
示例15: save
import org.hibernate.NonUniqueResultException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public synchronized void save(T element) throws LogicException {
try {
T priorObject = (T) makeCriteria(element.getUniqValue()).add(Restrictions.eq(START_DATE, element.getStartDate()))
.uniqueResult();
if (priorObject != null) {
session.delete(priorObject);
}
session.saveOrUpdate(element);
} catch (NonUniqueResultException e) {
throw LogicExceptionFormatted.format("Non-unique result when searching for objects at " + DATE_FORMAT, element.getStartDate());
}
}