I've recently run into an error in a spring-boot application, as follows:
2021/12/30 12:26:00.004 | ERROR | taskScheduler-2 | o.h.e.jdbc.spi.SqlExceptionHelper] | Unknown column 'remoteappt0_.productCode' in 'field list'
2021/12/30 12:26:00.006 | ERROR | taskScheduler-2 | o.s.s.s.TaskUtils$LoggingErrorHandler] | Unexpected error occurred in scheduled task.
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:279)```
...
at com.sun.proxy.$Proxy218.findAll(Unknown Source)
at com.sick.ap.components.broker.service.RemoteAppTokenService.getRemoteApps(RemoteAppTokenService.java:254)
at com.sick.ap.components.broker.config.TokenManagerScheduler.RemoteAppTokenAutoRefresh(TokenManagerScheduler.java:36)
at jdk.internal.reflect.GeneratedMethodAccessor519.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
...
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
...
Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'remoteappt0_.productCode' in 'field list'
Here's the part of the service class making the invocation:
@Override
public List<RemoteAppTokenEntity> getRemoteApps() {
return (List<RemoteAppTokenEntity>) remoteAppTokenRepository.findAll();
}
This is the Entity class :
/**
* The Class RemoteAppTokenEntity.
*/
@Entity
@Table(name = "ap_login_remote_app_token", uniqueConstraints = {
@UniqueConstraint(columnNames = { "url", "userName" }) })
public class RemoteAppTokenEntity implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -2527642887887743421L;
/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Long id;
/** The user name. */
@Column(name = "userName", nullable = false)
private String userName;
/** The pass word. */
@Column(name = "passWord", nullable = false)
private String passWord;
/** The refresh token. */
@Column(name = "refreshToken", nullable = false)
private String refreshToken;
/** The token type. */
@Column(name = "tokenType", nullable = false)
private String tokenType;
/** The token value. */
@Column(name = "tokenValue", nullable = false)
private String tokenValue;
/** The token expiration. */
@Column(name = "tokenExpiration", nullable = false)
private Date tokenExpiration;
/** The created by. */
@Column(name = "created_by", nullable = false)
protected String createdBy;
/** The created at. */
@Column(name = "created_at", nullable = false)
protected Date createdAt;
/** The updated by. */
@Column(name = "updated_by", nullable = false)
protected String updatedBy;
/** The updated at. */
@Column(name = "updated_at", nullable = false)
protected Date updatedAt;
/** The url. */
@Column(name = "url", nullable = false)
private String url;
/** The product code. */
@Column(name = "productCode", nullable = false)
private String productCode;
/**
* Instantiates a new remote app token entity.
*/
public RemoteAppTokenEntity() {
super();
}
/**
* Instantiates a new remote app token entity.
*
* @param id the id
* @param userName the user name
* @param passWord the pass word
* @param refreshToken the refresh token
* @param tokenType the token type
* @param tokenValue the token value
* @param tokenExpiration the token expiration
* @param createdBy the created by
* @param createdAt the created at
* @param updatedBy the updated by
* @param updatedAt the updated at
* @param url the url
* @param productCode the product code
*/
public RemoteAppTokenEntity(Long id, String userName, String passWord, String refreshToken, String tokenType,
String tokenValue, Date tokenExpiration, String createdBy, Date createdAt, String updatedBy, Date updatedAt,
String url, String productCode) {
super();
this.id = id;
this.userName = userName;
this.passWord = passWord;
this.refreshToken = refreshToken;
this.tokenType = tokenType;
this.tokenValue = tokenValue;
this.tokenExpiration = tokenExpiration;
this.createdBy = createdBy;
this.createdAt = createdAt;
this.updatedBy = updatedBy;
this.updatedAt = updatedAt;
this.url = url;
this.productCode = productCode;
}
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the user name.
*
* @return the user name
*/
public String getUserName() {
return userName;
}
/**
* Sets the user name.
*
* @param userName the new user name
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* Gets the pass word.
*
* @return the pass word
*/
public String getPassWord() {
return passWord;
}
/**
* Sets the pass word.
*
* @param passWord the new pass word
*/
public void setPassWord(String passWord) {
this.passWord = passWord;
}
/**
* Gets the refresh token.
*
* @return the refresh token
*/
public String getRefreshToken() {
return refreshToken;
}
/**
* Sets the refresh token.
*
* @param refreshToken the new refresh token
*/
public void setRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
}
/**
* Gets the token type.
*
* @return the token type
*/
public String getTokenType() {
return tokenType;
}
/**
* Sets the token type.
*
* @param tokenType the new token type
*/
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
/**
* Gets the token value.
*
* @return the token value
*/
public String getTokenValue() {
return tokenValue;
}
/**
* Sets the token value.
*
* @param tokenValue the new token value
*/
public void setTokenValue(String tokenValue) {
this.tokenValue = tokenValue;
}
/**
* Gets the token expiration.
*
* @return the token expiration
*/
public Date getTokenExpiration() {
return tokenExpiration;
}
/**
* Sets the token expiration.
*
* @param tokenExpiration the new token expiration
*/
public void setTokenExpiration(Date tokenExpiration) {
this.tokenExpiration = tokenExpiration;
}
/**
* Gets the created by.
*
* @return the created by
*/
public String getCreatedBy() {
return createdBy;
}
/**
* Sets the created by.
*
* @param createdBy the new created by
*/
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
/**
* Gets the created at.
*
* @return the created at
*/
public Date getCreatedAt() {
return createdAt;
}
/**
* Sets the created at.
*
* @param createdAt the new created at
*/
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
/**
* Gets the updated by.
*
* @return the updated by
*/
public String getUpdatedBy() {
return updatedBy;
}
/**
* Sets the updated by.
*
* @param updatedBy the new updated by
*/
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
/**
* Gets the updated at.
*
* @return the updated at
*/
public Date getUpdatedAt() {
return updatedAt;
}
/**
* Sets the updated at.
*
* @param updatedAt the new updated at
*/
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
/**
* Gets the url.
*
* @return the url
*/
public String getUrl() {
return url;
}
/**
* Sets the url.
*
* @param url the new url
*/
public void setUrl(String url) {
this.url = url;
}
/**
* Gets the serialversionuid.
*
* @return the serialversionuid
*/
public static long getSerialversionuid() {
return serialVersionUID;
}
/**
* @return the productCode
*/
public String getProductCode() {
return productCode;
}
/**
* @param productCode the productCode to set
*/
public void setProductCode(String productCode) {
this.productCode = productCode;
}
@Override
public String toString() {
return "RemoteAppTokenEntity [id=" + id + ", userName=" + userName + ", passWord=" + passWord
+ ", refreshToken=" + refreshToken + ", tokenType=" + tokenType + ", tokenValue=" + tokenValue
+ ", tokenExpiration=" + tokenExpiration + ", createdBy=" + createdBy + ", createdAt=" + createdAt
+ ", updatedBy=" + updatedBy + ", updatedAt=" + updatedAt + ", url=" + url + ", productCode="
+ productCode + "]";
}
}
Here is a mysql dump of table (currently empty):
The class generating the error invoked by a scheduler class on startup in this method:
/**
* Remote app token auto refresh.
*/
@Scheduled(cron = "${scheduler.remoteAppTokenAutoRefresh.timer}")
public void RemoteAppTokenAutoRefresh() {
List<RemoteAppTokenEntity> remoteAppList = remoteAppTokenService.getRemoteApps();
remoteAppList.stream().forEach(remoteAppToken -> {
try {
remoteAppTokenService.remoteAppTokenRefreshAndUpdate(remoteAppToken);
} catch (Exception e) {
LOGGER.error("Error Occurred in {} Remote app token refresh and update proccess",
remoteAppToken.getUrl());
LOGGER.error(e.getMessage());
LOGGER.debug(e.getMessage(), e);
}
});
}
I've tried dump the SQL statements, but it's not showing the one from this application, I think because it's a dependency of the end application.
Any ideas what the problem might be? I've been trying some things, but so far no luck.
Full stack trace:
2021/12/30 12:26:00.004 | ERROR | taskScheduler-2 | o.h.e.jdbc.spi.SqlExceptionHelper] | Unknown column 'remoteappt0_.productCode' in 'field list'
2021/12/30 12:26:00.006 | ERROR | taskScheduler-2 | o.s.s.s.TaskUtils$LoggingErrorHandler] | Unexpected error occurred in scheduled task.
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:279)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:253)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy218.findAll(Unknown Source)
at com.sick.ap.components.broker.service.RemoteAppTokenService.getRemoteApps(RemoteAppTokenService.java:254)
at com.sick.ap.components.broker.config.TokenManagerScheduler.RemoteAppTokenAutoRefresh(TokenManagerScheduler.java:36)
at jdk.internal.reflect.GeneratedMethodAccessor519.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:69)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2173)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1936)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1898)
at org.hibernate.loader.Loader.doQuery(Loader.java:937)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
at org.hibernate.loader.Loader.doList(Loader.java:2695)
at org.hibernate.loader.Loader.doList(Loader.java:2678)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2512)
at org.hibernate.loader.Loader.list(Loader.java:2507)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:224)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1511)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1561)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1529)
at org.hibernate.query.Query.getResultList(Query.java:168)
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:76)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:306)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:73)
at jdk.internal.reflect.GeneratedMethodAccessor343.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359)
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
... 23 common frames omitted
Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'remoteappt0_.productCode' in 'field list'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:536)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:115)
at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1983)
at com.mysql.cj.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1826)
at com.mysql.cj.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1923)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:431)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
... 59 common frames omitted
