[hibernate-issues] [Hibernate-JIRA] Resolved: (EJB-341) Trying to create unexisting named query set the transaction to rollback
Emmanuel Bernard (JIRA)
noreply at atlassian.com
Fri Feb 29 12:16:33 EST 2008
[ http://opensource.atlassian.com/projects/hibernate/browse/EJB-341?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Emmanuel Bernard resolved EJB-341.
----------------------------------
Resolution: Fixed
Fix Version/s: 3.3.2.ga
> 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
> Affects Versions: 3.3.1.GA
> Environment: Hibernate Core 3.2.2 GA
> Hibernate EntityManager 3.3.1 GA
> Reporter: Frederic Zgud
> Fix For: 3.3.2.ga
>
> Original Estimate: 30 minutes
> Remaining Estimate: 30 minutes
>
> 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