use of org.hibernate.NonUniqueResultException in project hibernate-orm by hibernate.
the class AbstractOneToOneMapper method nullSafeMapToEntityFromMap.
@Override
public void nullSafeMapToEntityFromMap(EnversService enversService, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) {
final EntityInfo referencedEntity = getEntityInfo(enversService, referencedEntityName);
Object value;
try {
value = queryForReferencedEntity(versionsReader, referencedEntity, (Serializable) primaryKey, revision);
} catch (NoResultException e) {
value = null;
} catch (NonUniqueResultException e) {
throw new AuditException("Many versions results for one-to-one relationship " + entityName + "." + getPropertyData().getBeanName() + ".", e);
}
setPropertyValue(obj, value);
}
use of org.hibernate.NonUniqueResultException in project hibernate-orm by hibernate.
the class AuditReaderImpl method getRevisionDate.
@Override
public Date getRevisionDate(Number revision) throws IllegalArgumentException, RevisionDoesNotExistException, IllegalStateException {
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionDateQuery(session, revision);
try {
final Object timestampObject = query.uniqueResult();
if (timestampObject == null) {
throw new RevisionDoesNotExistException(revision);
}
// The timestamp object is either a date or a long
return timestampObject instanceof Date ? (Date) timestampObject : new Date((Long) timestampObject);
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
}
use of org.hibernate.NonUniqueResultException in project hibernate-orm by hibernate.
the class AuditReaderImpl method findRevision.
@Override
@SuppressWarnings({ "unchecked" })
public <T> T findRevision(Class<T> revisionEntityClass, Number revision) throws IllegalArgumentException, RevisionDoesNotExistException, IllegalStateException {
revisionEntityClass = getTargetClassIfProxied(revisionEntityClass);
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
final Set<Number> revisions = new HashSet<>(1);
revisions.add(revision);
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions);
try {
final T revisionData = (T) query.uniqueResult();
if (revisionData == null) {
throw new RevisionDoesNotExistException(revision);
}
return revisionData;
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
}
use of org.hibernate.NonUniqueResultException in project hibernate-orm by hibernate.
the class AuditReaderImpl method getRevisionNumberForDate.
@Override
public Number getRevisionNumberForDate(Date date) {
checkNotNull(date, "Date of revision");
checkSession();
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery(session, date);
try {
final Number res = (Number) query.uniqueResult();
if (res == null) {
throw new RevisionDoesNotExistException(date);
}
return res;
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
}
use of org.hibernate.NonUniqueResultException in project hibernate-orm by hibernate.
the class AbstractProducedQuery method uniqueElement.
public static <R> R uniqueElement(List<R> list) throws NonUniqueResultException {
int size = list.size();
if (size == 0) {
return null;
}
R first = list.get(0);
for (int i = 1; i < size; i++) {
if (list.get(i) != first) {
throw new NonUniqueResultException(list.size());
}
}
return first;
}
Aggregations