
| Key: |
EJB-341
|
| Type: |
Bug
|
| Status: |
Resolved
|
| Resolution: |
Fixed
|
| Priority: |
Major
|
| Assignee: |
Unassigned
|
| Reporter: |
Frederic Zgud
|
| Votes: |
0
|
| Watchers: |
0
|
|
If you were logged in you would be able to see more operations.
|
|
|
|
Time Tracking:
|
|
Original Estimate:
|
30 minutes
|
|
|
Remaining Estimate:
|
30 minutes
|
|
|
Time Spent:
|
Not Specified
|
|
|
|
|
Environment:
|
Hibernate Core 3.2.2 GA
Hibernate EntityManager 3.3.1 GA
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
|
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.
|
|
Description
|
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. |
Show » |
Sort Order:
| There are no comments yet on this issue.
|
|