Skip to content

Commit

Permalink
improve some error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Jan 1, 2023
1 parent 76b2f92 commit e48a812
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
Expand Up @@ -18,7 +18,6 @@
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.LoadEvent;
import org.hibernate.event.spi.LoadEventListener;
Expand Down Expand Up @@ -65,9 +64,9 @@ public void onLoad(LoadEvent event, LoadType loadType) throws HibernateException
final Class<?> idClass = persister.getIdentifierType().getReturnedClass();
if ( handleIdType( persister, event, loadType, idClass) ) {
throw new TypeMismatchException(
"Provided id of the wrong type for class " + persister.getEntityName()
+ ". Expected: " + idClass
+ ", got " + event.getEntityId().getClass()
"Supplied id had wrong type: entity '" + persister.getEntityName()
+ "' has id type '" + idClass
+ "' but supplied id was of type '" + event.getEntityId().getClass() + "'"
);
}
}
Expand Down
Expand Up @@ -16,7 +16,7 @@
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;

/**
* A JdbcValuesSource implementation for cases where we had a cache hit.
* An {@link AbstractJdbcValues} implementation for cases where we had a cache hit.
*
* @author Steve Ebersole
*/
Expand Down Expand Up @@ -71,7 +71,11 @@ private static Object[][] extractData(List<?> cachedResults) {

@Override
protected boolean processNext(RowProcessingState rowProcessingState) {
ResultsLogger.RESULTS_MESSAGE_LOGGER.tracef( "JdbcValuesCacheHit#processNext : position = %i; numberOfRows = %i", position, numberOfRows );
ResultsLogger.RESULTS_MESSAGE_LOGGER.tracef(
"JdbcValuesCacheHit#processNext : position = %i; numberOfRows = %i",
position,
numberOfRows
);

// NOTE : explicitly skipping limit handling because the cached state ought
// already be the limited size since the cache key includes limits
Expand All @@ -88,7 +92,10 @@ protected boolean processNext(RowProcessingState rowProcessingState) {

@Override
protected boolean processPrevious(RowProcessingState rowProcessingState) {
ResultsLogger.RESULTS_MESSAGE_LOGGER.tracef( "JdbcValuesCacheHit#processPrevious : position = %i; numberOfRows = %i", position, numberOfRows );
ResultsLogger.RESULTS_MESSAGE_LOGGER.tracef(
"JdbcValuesCacheHit#processPrevious : position = %i; numberOfRows = %i",
position, numberOfRows
);

// NOTE : explicitly skipping limit handling because the cached state ought
// already be the limited size since the cache key includes limits
Expand All @@ -105,7 +112,10 @@ protected boolean processPrevious(RowProcessingState rowProcessingState) {

@Override
protected boolean processScroll(int numberOfRows, RowProcessingState rowProcessingState) {
ResultsLogger.RESULTS_MESSAGE_LOGGER.tracef( "JdbcValuesCacheHit#processScroll(%i) : position = %i; numberOfRows = %i", numberOfRows, position, this.numberOfRows );
ResultsLogger.RESULTS_MESSAGE_LOGGER.tracef(
"JdbcValuesCacheHit#processScroll(%i) : position = %i; numberOfRows = %i",
numberOfRows, position, this.numberOfRows
);

// NOTE : explicitly skipping limit handling because the cached state should
// already be the limited size since the cache key includes limits
Expand All @@ -127,7 +137,10 @@ public int getPosition() {

@Override
protected boolean processPosition(int position, RowProcessingState rowProcessingState) {
ResultsLogger.RESULTS_MESSAGE_LOGGER.tracef( "JdbcValuesCacheHit#processPosition(%i) : position = %i; numberOfRows = %i", position, this.position, this.numberOfRows );
ResultsLogger.RESULTS_MESSAGE_LOGGER.tracef(
"JdbcValuesCacheHit#processPosition(%i) : position = %i; numberOfRows = %i",
position, this.position, this.numberOfRows
);

// NOTE : explicitly skipping limit handling because the cached state should
// already be the limited size since the cache key includes limits
Expand Down
Expand Up @@ -10,7 +10,6 @@
import java.sql.SQLException;
import java.util.Arrays;

import org.hibernate.HibernateException;
import org.hibernate.cache.spi.QueryKey;
import org.hibernate.cache.spi.QueryResultsCache;
import org.hibernate.engine.spi.SessionFactoryImplementor;
Expand All @@ -27,7 +26,7 @@
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;

/**
* JdbcValuesSource implementation for a JDBC ResultSet as the source
* {@link AbstractJdbcValues} implementation for a JDBC {@link ResultSet} as the source
*
* @author Steve Ebersole
*/
Expand Down Expand Up @@ -247,7 +246,7 @@ private boolean advance(final boolean hasResult) {

private ExecutionException makeExecutionException(String message, SQLException cause) {
return new ExecutionException(
message,
message + " [" + cause.getMessage() + "]",
executionContext.getSession().getJdbcServices().getSqlExceptionHelper().convert(
cause,
message
Expand All @@ -266,10 +265,11 @@ private void readCurrentRowValues() {
session
);
}
catch (Exception e) {
throw new HibernateException(
"Unable to extract JDBC value for position `" + sqlSelection.getJdbcResultSetIndex() + "`",
e
catch ( SQLException e ) {
// do not want to wrap in ExecutionException here
throw executionContext.getSession().getJdbcServices().getSqlExceptionHelper().convert(
e,
"Could not extract column [" + sqlSelection.getJdbcResultSetIndex() + "] from JDBC ResultSet"
);
}
}
Expand All @@ -293,9 +293,9 @@ public Object[] getCurrentRowValuesArray() {
@Override
public void setFetchSize(int fetchSize) {
try {
resultSetAccess.getResultSet().setFetchSize(fetchSize);
resultSetAccess.getResultSet().setFetchSize( fetchSize );
}
catch (SQLException e) {
catch ( SQLException e ) {
throw makeExecutionException( "Error calling ResultSet.setFetchSize()", e );
}
}
Expand Down

0 comments on commit e48a812

Please sign in to comment.