Issue Details (XML | Word | Printable)

Key: EJB-341
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Frederic Zgud
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
z - Hibernate Entity Manager

Trying to create unexisting named query set the transaction to rollback

Created: 29/Feb/08 10:30 AM   Updated: 29/Feb/08 11:15 AM   Resolved: 29/Feb/08 11:15 AM
Component/s: EntityManager
Affects Version/s: 3.3.1.GA
Fix Version/s: 3.3.2.CR1

Time Tracking:
Original Estimate: 30 minutes
Original Estimate - 30 minutes
Remaining Estimate: 30 minutes
Remaining Estimate - 30 minutes
Time Spent: Not Specified
Time Spent - Not Specified

Environment:
Hibernate Core 3.2.2 GA
Hibernate EntityManager 3.3.1 GA

Bug Testcase Reminder (view):
REMINDER: Bug reports should generally be accompanied by a test case
Participants: Frederic Zgud


 Description  « Hide

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.



There are no comments yet on this issue.