[hibernate-issues] [Hibernate-JIRA] Created: (EJB-341) Trying to create unexisting named query set the transaction to rollback

Frederic Zgud (JIRA) noreply at atlassian.com
Fri Feb 29 11:31:33 EST 2008


Trying to create unexisting named query set the transaction to rollback
-----------------------------------------------------------------------

                 Key: EJB-341
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-341
             Project: Hibernate Entity Manager
          Issue Type: Bug
          Components: EntityManager
         Environment: Hibernate Core 	 3.2.2 GA
Hibernate EntityManager 	 3.3.1 GA
            Reporter: Frederic Zgud


Trying to create a named query that doesn't exist raises a PersistenceException, instead of the IllegalArgumentException specified in JPA ( http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html#createNamedQuery(java.lang.String) ), and sets the current transaction to rollback. This is a non sens.

Source code of AbstractEntityManagerImpl :
...
	public Query createNamedQuery(String name) {
		//adjustFlushMode();
		try {
			return new QueryImpl( getSession().getNamedQuery( name ), this );
		}
		catch (HibernateException he) {
			throwPersistenceException( he );
			return null;
		}
	}

The exception is raised in class AbstractSessionImpl (hibernate 3 project) :
...
	public Query getNamedQuery(String queryName) throws MappingException {
		errorIfClosed();
		NamedQueryDefinition nqd = factory.getNamedQuery( queryName );
		final Query query;
		if ( nqd != null ) {
			String queryString = nqd.getQueryString();
			query = new QueryImpl(
					queryString,
			        nqd.getFlushMode(),
			        this,
			        getHQLQueryPlan( queryString, false ).getParameterMetadata()
			);
			query.setComment( "named HQL query " + queryName );
		}
		else {
			NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
			if ( nsqlqd==null ) {
>>>				throw new MappingException( "Named query not known: " + queryName );     <<<<< There
			}
			query = new SQLQueryImpl(
					nsqlqd,
			        this,
			        factory.getQueryPlanCache().getSQLParameterMetadata( nsqlqd.getQueryString() )
			);
			query.setComment( "named native SQL query " + queryName );
			nqd = nsqlqd;
		}
		initQuery( query, nqd );
		return query;
	}
...

Maybe the line
>>>				throw new MappingException( "Named query not known: " + queryName );     <<<<< There
could be replaced by
				throw new MappingNotFoundException( "Named query not known: " + queryName );   
or another MappingException subclass and this exception catched in AbstractEntityManagerImpl :

	public Query createNamedQuery(String name) {
		//adjustFlushMode();
		try {
			return new QueryImpl( getSession().getNamedQuery( name ), this );
		}
		catch (MappingNotFoundException mnfe) {
			throw new IllegalArgumentException( mnfe );
		}
		catch (HibernateException he) {
			throwPersistenceException( he );
			return null;
		}
	}

leaving the transaction open.

-- 
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