[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3117) Proposal for better (more speaking) Exceptions

Daniel Migowski (JIRA) noreply at atlassian.com
Tue Feb 19 06:11:33 EST 2008


Proposal for better (more speaking) Exceptions
----------------------------------------------

                 Key: HHH-3117
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3117
             Project: Hibernate3
          Issue Type: Improvement
          Components: core
    Affects Versions: 3.2.5
            Reporter: Daniel Migowski
            Priority: Minor


Currently I get LazyInitializationExceptions in my Logfiles. To debug them, it would be great to know from with lazy objects they originate. To achive this I currently override the AbstractLazyInitializer class and add the entityName and Id to the ExceptionText. The modified source is like this (Just the exception messages have been modified):

    public final void initialize() throws HibernateException {
        if (!initialized) {
            if ( session==null ) {
                throw new LazyInitializationException("could not initialize proxy for "+entityName+"("+id+") - no Session");
            }
            else if ( !session.isOpen() ) {
                throw new LazyInitializationException("could not initialize proxy for "+entityName+"("+id+") - the owning Session was closed");
            }
            else if ( !session.isConnected() ) {
                throw new LazyInitializationException("could not initialize proxy for "+entityName+"("+id+") - the owning Session is disconnected");
            }
            else {
                target = session.immediateLoad(entityName, id);
                initialized = true;
                checkTargetState();
            }
        }
        else {
            checkTargetState();
        }
    }

    private void checkTargetState() {
        if ( !unwrap ) {
            if ( target == null ) {
                getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( entityName, id );
            }
        }
    }

    public final void setSession(SessionImplementor s) throws HibernateException {
        if (s!=session) {
            if ( isConnectedToSession() ) {
                //TODO: perhaps this should be some other RuntimeException...
                throw new HibernateException("illegally attempted to associate a proxy for "+entityName+"("+id+") with two open Sessions");
            }
            session = s;
        }
    }



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list