简体   繁体   English

使用Spring Boot Application时如何解决PostgreSQL问题

[英]How to resolve PostgreSQL issue when using Spring Boot Application

I have a project which is built from several maven modules. 我有一个由几个Maven模块构建的项目。 These modules include logic to clear down, populate and validate the contents of a PostgreSQL database. 这些模块包括清除,填充和验证PostgreSQL数据库内容的逻辑。

The lower level modules all work fine, but my top level Spring Boot Application is currently failing due to the following error: 较低层的模块都可以正常工作,但是我的高层Spring Boot应用程序当前由于以下错误而失败:

Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2065)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
at org.hibernate.loader.Loader.doQuery(Loader.java:909)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
at org.hibernate.loader.Loader.doList(Loader.java:2553)
at org.hibernate.loader.Loader.doList(Loader.java:2539)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369)
at org.hibernate.loader.Loader.list(Loader.java:2364)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:496)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:231)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:495)
at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getSingleResult(CriteriaQueryTypeQueryAdapter.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:362)
at com.sun.proxy.$Proxy104.getSingleResult(Unknown Source)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:202)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:74)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:99)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:90)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:415)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:393)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy74.findByUserNameIgnoreCase(Unknown Source)
at org.credmins.cornerstone.model.initialise.CornerstoneDBInit.createItemsIfNoKeyUsersExist(CornerstoneDBInit.java:69)
at org.credmins.cornerstone.model.initialise.RunDBInitialiserWhenNeeded.onApplicationEvent(RunDBInitialiserWhenNeeded.java:21)
at org.credmins.cornerstone.model.initialise.RunDBInitialiserWhenNeeded.onApplicationEvent(RunDBInitialiserWhenNeeded.java:16)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:775)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:103)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:170)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:110)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:259)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:261)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:219)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: org.postgresql.util.PSQLException: ERROR: column userrecord0_.created_by_user_uuid does not exist
  Position: 36
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2065

The stack trace is pointing me to this key line: 堆栈跟踪将我指向以下关键行:

org.postgresql.util.PSQLException: ERROR: column userrecord0_.created_by_user_uuid does not exist

The test which fails is as follows: 失败的测试如下:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = CornerstoneApplication.class)
@WebAppConfiguration
public class CornerstoneApplicationTest {

@Test    
public void contextLoads() {  }
}

The application is: 该应用程序是:

@SpringBootApplication
public class CornerstoneApplication {
    public static void main(String[] args) {
        SpringApplication.run(CornerstoneApplication.class, args);
    }
}

Looking at the underlying data, the first data record in the userrecord file does not have a created_by_user_uuid, but looking at the entity record, this field is not mandatory 查看基础数据, userrecord文件中的第一个数据记录没有created_by_user_uuid,但是查看实体记录,此字段不是必需的

UserRecord: 用户记录:

@Entity
@Table(name = "users")
public class UserRecord extends AbstractKeyedRecord implements Record {

    @Nonnull
    @Column(unique = true)
    private String userName;
    @Nonnull
    private String firstName;
    @Nonnull
    private String lastName;
<truncated>

AbstractKeyedRecord: AbstractKeyedRecord:

@MappedSuperclass
public abstract class AbstractKeyedRecord extends AbstractRecord {
    @Id
    @org.hibernate.annotations.Type(type = "pg-uuid")
    private UUID id;
<truncated>

AbstractRecord: 摘要记录:

@MappedSuperclass
public abstract class AbstractRecord implements Serializable, Record {
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime createdDate;
@org.hibernate.annotations.Type(type = "pg-uuid")
private UUID createdByUserUuid;

@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime lastUpdatedDate;
@org.hibernate.annotations.Type(type = "pg-uuid")
private UUID lastUpdatedUserUuid;

public AbstractRecord() {
}
<truncated>

Record: 记录:

public interface Record {}

Probably the most frustrating thing of all is that I have had this working before, but recently moved from xml config files to use config classes, and the ApplicationTest has not worked since. 可能最令人沮丧的是,我之前曾经做过这项工作,但是最近从xml配置文件转移到使用配置类,而ApplicationTest从此一直没有工作。

So, my question is can anyone suggest steps I could take to resolve resolve this issue ? 因此,我的问题是,有人可以建议我采取一些解决措施来解决此问题吗?

I think you are connecting to some other DB that doesn't have the 'created_by_user_uuid' column. 我认为您正在连接到其他没有'created_by_user_uuid'列的数据库。 Especially because it was working with XML config. 特别是因为它正在使用XML配置。
Check your database connection configuration. 检查您的数据库连接配置。 You could set the DB connection password to a wrong password to be sure that you are really connecting to the configured DB. 您可以将数据库连接密码设置为错误的密码,以确保您确实连接到已配置的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决 spring 启动应用程序中的 CORS 问题? - How to resolve CORS issue in spring boot application? 使用 Spring boot + Postgresql 时使用索引 - Working with indexes when using Spring boot + Postgresql 如果 Spring 引导应用程序返回字符串值而不是 JSP 页面,如何解决该问题 - How to resolve the issue if Spring Boot Application returns string value instead of JSP page 如何在使用 spring 启动应用程序的 jar 包装时使用 SpringBootServletInitializer - How to use SpringBootServletInitializer when using a jar packaging for spring boot application 使用多租户时的Spring Boot作用域问题 - Spring boot scope issue when using multitenancy 如何解决 Spring Boot 应用程序中与“Whitelabel Error Page”相关的问题 - How to resolve the problem related to "Whitelabel Error Page" in a Spring Boot application 如何在云端Jelastic上使用PostgreSQL部署Spring Boot应用程序? - How to deploy Spring Boot application with PostgreSQL on the cloud Jelastic? 使用Spring Boot将数据插入表时,如何解决外键始终为零的问题? - How to resolve the problem of foreign key of being zero all time when data inserted to tables using spring boot? 如何解决春季问题 - how to resolve spring issue Spring 引导应用程序部署问题 - Spring Boot Application Deployment Issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM