Java 类org.hibernate.UnresolvableObjectException 实例源码

项目:oma-riista-web    文件:Person.java   
@Nonnull
public LocalisedString getHomeMunicipalityName() {
    if (this.homeMunicipality != null) {
        if (!Hibernate.isInitialized(this.homeMunicipality)) {
            try {
                // Referenced row might not exist
                return this.homeMunicipality.getNameLocalisation();
            } catch (UnresolvableObjectException | EntityNotFoundException o) {
                this.homeMunicipality = null;
            }
        } else {
            return this.homeMunicipality.getNameLocalisation();
        }
    }
    return LocalisedString.EMPTY;
}
项目:eMonocot    文件:DaoImpl.java   
/**
 * @param id
 *            Set the id
 * @param fetch
 *            Set the fetch profile (can be null)
 * @return the loaded object
 */
public T load(final Long id, final String fetch) {

    Criteria criteria = getSession().createCriteria(type).add(
            Restrictions.idEq(id));

    enableProfilePreQuery(criteria, fetch);

    T t = (T) criteria.uniqueResult();

    if (t == null) {
        throw new HibernateObjectRetrievalFailureException(
                new UnresolvableObjectException(id,
                        "Object could not be resolved"));
    }
    enableProfilePostQuery(t, fetch);
    return t;
}
项目:eMonocot    文件:DaoImpl.java   
/**
 * @param identifier
 *            Set the identifier
 * @param fetch
 *            Set the fetch profile (can be null)
 * @return the loaded object
 */
public T load(final String identifier, final String fetch) {

    Criteria criteria = getSession().createCriteria(type).add(
            Restrictions.eq("identifier", identifier));

    enableProfilePreQuery(criteria, fetch);

    T t = (T) criteria.uniqueResult();

    if (t == null) {
        throw new HibernateObjectRetrievalFailureException(
                new UnresolvableObjectException(identifier,
                        "Object could not be resolved"));
    }
    enableProfilePostQuery(t, fetch);
    return t;
}
项目:cosmo    文件:ItemDaoImpl.java   
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);
    }
}
项目:lams    文件:SessionImpl.java   
@Override
public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException {
    // todo : remove
    LoadEventListener.LoadType type = nullable
            ? LoadEventListener.INTERNAL_LOAD_NULLABLE
            : eager
                    ? LoadEventListener.INTERNAL_LOAD_EAGER
                    : LoadEventListener.INTERNAL_LOAD_LAZY;
    LoadEvent event = new LoadEvent(id, entityName, true, this);
    fireLoad( event, type );
    if ( !nullable ) {
        UnresolvableObjectException.throwIfNull( event.getResult(), id, entityName );
    }
    return event.getResult();
}
项目:lams    文件:StatelessSessionImpl.java   
@Override
    public void refresh(String entityName, Object entity, LockMode lockMode) {
        final EntityPersister persister = this.getEntityPersister( entityName, entity );
        final Serializable id = persister.getIdentifier( entity, this );
        if ( LOG.isTraceEnabled() ) {
            LOG.tracev( "Refreshing transient {0}", MessageHelper.infoString( persister, id, this.getFactory() ) );
        }
        // TODO : can this ever happen???
//      EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
//      if ( source.getPersistenceContext().getEntry( key ) != null ) {
//          throw new PersistentObjectException(
//                  "attempted to refresh transient instance when persistent " +
//                  "instance was already associated with the Session: " +
//                  MessageHelper.infoString( persister, id, source.getFactory() )
//          );
//      }

        if ( persister.hasCache() ) {
            final CacheKey ck = generateCacheKey( id, persister.getIdentifierType(), persister.getRootEntityName() );
            persister.getCacheAccessStrategy().evict( ck );
        }

        String previousFetchProfile = this.getFetchProfile();
        Object result = null;
        try {
            this.setFetchProfile( "refresh" );
            result = persister.load( id, entity, lockMode, this );
        }
        finally {
            this.setFetchProfile( previousFetchProfile );
        }
        UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
    }
项目:cacheonix-core    文件:SessionImpl.java   
public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException {
    // todo : remove
    LoadEventListener.LoadType type = nullable ? 
            LoadEventListener.INTERNAL_LOAD_NULLABLE : 
            eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
    LoadEvent event = new LoadEvent(id, entityName, true, this);
    fireLoad(event, type);
    if ( !nullable ) {
        UnresolvableObjectException.throwIfNull( event.getResult(), id, entityName );
    }
    return event.getResult();
}
项目:oStorybook    文件:StrandLinksPanel.java   
@Override
public void initUi() {
    setLayout(new MigLayout("insets 2"));
    if (opaque) {
        setOpaque(true);
        setBackground(scene.getStrand().getJColor());
    } else {
        setOpaque(false);
    }
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    session.refresh(scene);
    List<Strand> list = scene.getStrands();
    if (list != null) {
        Collections.sort(list);
    }
    for (Strand strand : list) {
        try {
            session.refresh(strand);
        } catch (UnresolvableObjectException e) {
            e.printStackTrace();
            continue;
        }
        CleverLabel lb = new CleverLabel(strand.getAbbreviation(),
                JLabel.CENTER);
        lb.setToolTipText(EntityUtil.getToolTip(strand));
        lb.setBackground(strand.getJColor());
        add(lb, "w 30");
    }
    model.commit();
}
项目:SE-410-Project    文件:StrandLinksPanel.java   
@Override
public void initUi() {
    setLayout(new MigLayout("insets 2"));
    if (opaque) {
        setOpaque(true);
        setBackground(scene.getStrand().getJColor());
    } else {
        setOpaque(false);
    }
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    session.refresh(scene);
    List<Strand> list = scene.getStrands();
    if (list != null) {
        Collections.sort(list);
    }
    for (Strand strand : list) {
        try {
            session.refresh(strand);
        } catch (UnresolvableObjectException e) {
            e.printStackTrace();
            continue;
        }
        CleverLabel lb = new CleverLabel(strand.getAbbreviation(),
                JLabel.CENTER);
        lb.setToolTipText(EntityUtil.getToolTip(strand));
        lb.setBackground(strand.getJColor());
        add(lb, "w 30");
    }
    model.commit();
}
项目:lams    文件:HibernateObjectRetrievalFailureException.java   
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
    super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
项目:lams    文件:HibernateObjectRetrievalFailureException.java   
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
    super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
项目:lams    文件:StandardQueryCache.java   
@Override
@SuppressWarnings({ "unchecked" })
public List get(
        final QueryKey key,
        final Type[] returnTypes,
        final boolean isNaturalKeyLookup,
        final Set<Serializable> spaces,
        final SessionImplementor session) throws HibernateException {
    if ( DEBUGGING ) {
        LOG.debugf( "Checking cached query results in region: %s", cacheRegion.getName() );
    }

    final List cacheable = getCachedResults( key, session );
    logCachedResultDetails( key, spaces, returnTypes, cacheable );

    if ( cacheable == null ) {
        if ( DEBUGGING ) {
            LOG.debug( "Query results were not found in cache" );
        }
        return null;
    }

    final Long timestamp = (Long) cacheable.get( 0 );
    if ( !isNaturalKeyLookup && !isUpToDate( spaces, timestamp, session ) ) {
        if ( DEBUGGING ) {
            LOG.debug( "Cached query results were not up-to-date" );
        }
        return null;
    }

    if ( DEBUGGING ) {
        LOG.debug( "Returning cached query results" );
    }
    final boolean singleResult = returnTypes.length == 1;
    for ( int i = 1; i < cacheable.size(); i++ ) {
        if ( singleResult ) {
            returnTypes[0].beforeAssemble( (Serializable) cacheable.get( i ), session );
        }
        else {
            TypeHelper.beforeAssemble( (Serializable[]) cacheable.get( i ), returnTypes, session );
        }
    }

    final List result = new ArrayList( cacheable.size() - 1 );
    for ( int i = 1; i < cacheable.size(); i++ ) {
        try {
            if ( singleResult ) {
                result.add( returnTypes[0].assemble( (Serializable) cacheable.get( i ), session, null ) );
            }
            else {
                result.add(
                        TypeHelper.assemble( (Serializable[]) cacheable.get( i ), returnTypes, session, null )
                );
            }
            logCachedResultRowDetails( returnTypes, result.get( i - 1 ) );
        }
        catch ( RuntimeException ex ) {
            if ( isNaturalKeyLookup ) {
                // potentially perform special handling for natural-id look ups.
                if ( UnresolvableObjectException.class.isInstance( ex )
                        || EntityNotFoundException.class.isInstance( ex ) ) {
                    if ( DEBUGGING ) {
                        LOG.debug( "Unable to reassemble cached natural-id query result" );
                    }
                    cacheRegion.evict( key );

                    // EARLY EXIT !!!!!
                    return null;
                }
            }
            throw ex;
        }
    }
    return result;
}
项目:spring4-understanding    文件:HibernateObjectRetrievalFailureException.java   
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
    super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
项目:spring4-understanding    文件:HibernateObjectRetrievalFailureException.java   
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
    super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
项目:spring4-understanding    文件:HibernateObjectRetrievalFailureException.java   
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
    super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
项目:cacheonix-core    文件:StandardQueryCache.java   
public List get(
        QueryKey key,
        Type[] returnTypes,
        boolean isNaturalKeyLookup,
        Set spaces,
        SessionImplementor session) throws HibernateException {
    if ( log.isDebugEnabled() ) {
        log.debug("checking cached query results in region: " + regionName);
    }

    List cacheable = (List) queryCache.get(key);
    if (cacheable==null) {
        log.debug("query results were not found in cache");
        return null;
    }

    Long timestamp = (Long) cacheable.get(0);
    if ( !isNaturalKeyLookup && !isUpToDate(spaces, timestamp) ) {
        log.debug("cached query results were not up to date");
        return null;
    }

    log.debug("returning cached query results");
    for ( int i=1; i<cacheable.size(); i++ ) {
        if ( returnTypes.length==1 ) {
            returnTypes[0].beforeAssemble( (Serializable) cacheable.get(i), session );
        }
        else {
            TypeFactory.beforeAssemble( (Serializable[]) cacheable.get(i), returnTypes, session );
        }
    }
    List result = new ArrayList( cacheable.size()-1 );
    for ( int i=1; i<cacheable.size(); i++ ) {
        try {
            if ( returnTypes.length==1 ) {
                result.add( returnTypes[0].assemble( (Serializable) cacheable.get(i), session, null ) );
            }
            else {
                result.add( TypeFactory.assemble( (Serializable[]) cacheable.get(i), returnTypes, session, null ) );
            }
        }
        catch (UnresolvableObjectException uoe) {
            if (isNaturalKeyLookup) {
                //TODO: not really completely correct, since
                //      the uoe could occur while resolving
                //      associations, leaving the PC in an
                //      inconsistent state
                log.debug("could not reassemble cached result set");
                queryCache.remove(key);
                return null;
            }
            else {
                throw uoe;
            }
        }
    }
    return result;
}
项目:cacheonix-core    文件:StatelessSessionImpl.java   
public void refresh(String entityName, Object entity, LockMode lockMode) {
        final EntityPersister persister = this.getEntityPersister( entityName, entity );
        final Serializable id = persister.getIdentifier( entity, getEntityMode() );
        if ( log.isTraceEnabled() ) {
            log.trace(
                    "refreshing transient " +
                    MessageHelper.infoString( persister, id, this.getFactory() )
            );
        }
        // TODO : can this ever happen???
//      EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
//      if ( source.getPersistenceContext().getEntry( key ) != null ) {
//          throw new PersistentObjectException(
//                  "attempted to refresh transient instance when persistent " +
//                  "instance was already associated with the Session: " +
//                  MessageHelper.infoString( persister, id, source.getFactory() )
//          );
//      }

        if ( persister.hasCache() ) {
            final CacheKey ck = new CacheKey(
                    id,
                    persister.getIdentifierType(),
                    persister.getRootEntityName(),
                    this.getEntityMode(),
                    this.getFactory()
            );
            persister.getCache().remove(ck);
        }

        String previousFetchProfile = this.getFetchProfile();
        Object result = null;
        try {
            this.setFetchProfile( "refresh" );
            result = persister.load( id, entity, lockMode, this );
        }
        finally {
            this.setFetchProfile( previousFetchProfile );
        }
        UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
    }
项目:oStorybook    文件:LocationLinksPanel.java   
@Override
public void initUi() {
    setLayout(new MigLayout("insets 0", "grow"));
    JTextArea ta = new JTextArea();
    ta.setLineWrap(true);
    ta.setWrapStyleWord(true);
    ta.setEditable(false);
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    session.refresh(scene);
    List<Location> locations = scene.getLocations();
    if (locations != null) {
        Collections.sort(locations);
    }
    int c = 0;
    for (Location location : locations) {
        try {
            session.refresh(location);
        } catch (UnresolvableObjectException e) {
            e.printStackTrace();
            continue;
        }
        ta.append(location.toString());
        if (c < locations.size() - 1) {
            ta.append(", ");
        }
        ++c;
    }
    model.commit();

    if (setSize) {
        JScrollPane scroller = new JScrollPane();
        scroller.setViewportView(ta);
        scroller.setBorder(null);
        if (setSize) {
            scroller.setMinimumSize(new Dimension(100, 30));
            scroller.setPreferredSize(new Dimension(170, 30));
        }
        SwingUtil.setUnitIncrement(scroller);
        scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        ta.setCaretPosition(0);
        add(scroller, "grow");
    } else {
        add(ta, "grow");
    }
}
项目:oStorybook    文件:PersonLinksPanel.java   
@Override
public void initUi() {
    if (vertical) {
        setLayout(new MigLayout("wrap 2,insets 0"));
    } else {
        setLayout(new MigLayout("flowx,insets 0"));
        setMaximumSize(new Dimension(170, 50));
    }
    setOpaque(false);
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    session.refresh(scene);
    List<Person> list = scene.getPersons();
    if (list != null) {
        Collections.sort(list);
    }
    for (Person person : list) {
        try {
            session.refresh(person);
        } catch (UnresolvableObjectException e) {
            e.printStackTrace();
            continue;
        }
        Color color = person.getJColor();
        JLabel lbName = new JLabel(person.getFullName());
        CleverLabel lbAbbr = new CleverLabel(person.getAbbreviation());
        lbAbbr.setToolTipText(EntityUtil.getToolTip(person, scene.getDate()));
        if (color != null) {
            lbAbbr.setBackground(color);
        } else {
            lbAbbr.setOpaque(false);
        }
        if (vertical) {
            add(lbAbbr);
            add(lbName);
        } else {
            add(lbAbbr, "gap 0");
        }
    }
    model.commit();
}
项目:SE-410-Project    文件:LocationLinksPanel.java   
@Override
public void initUi() {
    setLayout(new MigLayout("insets 0", "grow"));
    JTextArea ta = new JTextArea();
    ta.setLineWrap(true);
    ta.setWrapStyleWord(true);
    ta.setEditable(false);
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    session.refresh(scene);
    List<Location> locations = scene.getLocations();
    if (locations != null) {
        Collections.sort(locations);
    }
    int c = 0;
    for (Location location : locations) {
        try {
            session.refresh(location);
        } catch (UnresolvableObjectException e) {
            e.printStackTrace();
            continue;
        }
        ta.append(location.toString());
        if (c < locations.size() - 1) {
            ta.append(", ");
        }
        ++c;
    }
    model.commit();

    if (setSize) {
        JScrollPane scroller = new JScrollPane();
        scroller.setViewportView(ta);
        scroller.setBorder(null);
        if (setSize) {
            scroller.setMinimumSize(new Dimension(100, 30));
            scroller.setPreferredSize(new Dimension(170, 30));
        }
        SwingUtil.setUnitIncrement(scroller);
        scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        ta.setCaretPosition(0);
        add(scroller, "grow");
    } else {
        add(ta, "grow");
    }
}
项目:SE-410-Project    文件:PersonLinksPanel.java   
@Override
public void initUi() {
    if (vertical) {
        setLayout(new MigLayout("wrap 2,insets 0"));
    } else {
        setLayout(new MigLayout("flowx,insets 0"));
        setMaximumSize(new Dimension(170, 50));
    }
    setOpaque(false);
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    session.refresh(scene);
    List<Person> list = scene.getPersons();
    if (list != null) {
        Collections.sort(list);
    }
    for (Person person : list) {
        try {
            session.refresh(person);
        } catch (UnresolvableObjectException e) {
            e.printStackTrace();
            continue;
        }
        Color color = person.getJColor();
        JLabel lbName = new JLabel(person.getFullName());
        CleverLabel lbAbbr = new CleverLabel(person.getAbbreviation());
        lbAbbr.setToolTipText(EntityUtil.getToolTip(person, scene.getDate()));
        if (color != null) {
            lbAbbr.setBackground(color);
        } else {
            lbAbbr.setOpaque(false);
        }
        if (vertical) {
            add(lbAbbr);
            add(lbName);
        } else {
            add(lbAbbr, "gap 0");
        }
    }
    model.commit();
}
项目:class-guard    文件:HibernateObjectRetrievalFailureException.java   
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
    super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
项目:class-guard    文件:HibernateObjectRetrievalFailureException.java   
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
    super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}