Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用JPA和derby数据库启动spring启动应用程序时出现“找不到表”错误_Java_Spring_Hibernate_Spring Boot_Jpa - Fatal编程技术网

Java 使用JPA和derby数据库启动spring启动应用程序时出现“找不到表”错误

Java 使用JPA和derby数据库启动spring启动应用程序时出现“找不到表”错误,java,spring,hibernate,spring-boot,jpa,Java,Spring,Hibernate,Spring Boot,Jpa,我正在创建一个非常简单的spring启动应用程序。我有一个主题类,它是一个实体,我编写了一个名为TopicService的服务,并使用crudepository方法执行crud操作。当我启动我的应用程序时,我在控制台中收到以下消息: . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)

我正在创建一个非常简单的spring启动应用程序。我有一个主题类,它是一个实体,我编写了一个名为TopicService的服务,并使用crudepository方法执行crud操作。当我启动我的应用程序时,我在控制台中收到以下消息:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.2.RELEASE)

2019-11-19 22:38:59.611  INFO 9476 --- [           main] i.j.s.CourseApiDataApplication           : Starting CourseApiDataApplication on DESKTOP-EL3JT6U with PID 9476 (C:\Users\HP\LearnSpringBoot\Course-api-data\target\classes started by HP in C:\Users\HP\LearnSpringBoot\Course-api-data)
2019-11-19 22:38:59.656  INFO 9476 --- [           main] i.j.s.CourseApiDataApplication           : No active profile set, falling back to default profiles: default
2019-11-19 22:38:59.821  INFO 9476 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@64cd705f: startup date [Tue Nov 19 22:38:59 PST 2019]; root of context hierarchy
2019-11-19 22:39:03.887  INFO 9476 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$1f7adbdb] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-19 22:39:05.050  INFO 9476 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2019-11-19 22:39:05.069  INFO 9476 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2019-11-19 22:39:05.073  INFO 9476 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
2019-11-19 22:39:05.330  INFO 9476 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-11-19 22:39:05.331  INFO 9476 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 5514 ms
2019-11-19 22:39:05.734  INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2019-11-19 22:39:05.743  INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-11-19 22:39:05.743  INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-11-19 22:39:05.747  INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-11-19 22:39:05.747  INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2019-11-19 22:39:06.217  INFO 9476 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-11-19 22:39:06.258  INFO 9476 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2019-11-19 22:39:06.452  INFO 9476 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.11.Final}
2019-11-19 22:39:06.453  INFO 9476 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2019-11-19 22:39:06.458  INFO 9476 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2019-11-19 22:39:06.563  INFO 9476 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-11-19 22:39:08.653  INFO 9476 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
2019-11-19 22:39:10.542  INFO 9476 --- [           main] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2019-11-19 22:39:10.732  INFO 9476 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: Topic
2019-11-19 22:39:10.745  INFO 9476 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: Topic
2019-11-19 22:39:11.101  INFO 9476 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-11-19 22:39:12.429  INFO 9476 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@64cd705f: startup date [Tue Nov 19 22:38:59 PST 2019]; root of context hierarchy
2019-11-19 22:39:12.614  INFO 9476 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics/{id}],methods=[PUT]}" onto public void io.javabrains.springbootstarter.Topic.TopicController.updateTopic(io.javabrains.springbootstarter.Topic.Topic,int)
2019-11-19 22:39:12.614  INFO 9476 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics],methods=[POST]}" onto public void io.javabrains.springbootstarter.Topic.TopicController.addTopic(io.javabrains.springbootstarter.Topic.Topic)
2019-11-19 22:39:12.618  INFO 9476 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics/{id}],methods=[DELETE]}" onto public void io.javabrains.springbootstarter.Topic.TopicController.deleteTopic(int)
2019-11-19 22:39:12.619  INFO 9476 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics/{id}]}" onto public io.javabrains.springbootstarter.Topic.Topic io.javabrains.springbootstarter.Topic.TopicController.getSingleTopic(int)
2019-11-19 22:39:12.619  INFO 9476 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics]}" onto public java.util.List<io.javabrains.springbootstarter.Topic.Topic> io.javabrains.springbootstarter.Topic.TopicController.getAllTopics()
2019-11-19 22:39:12.623  INFO 9476 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-11-19 22:39:12.623  INFO 9476 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-11-19 22:39:12.704  INFO 9476 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-11-19 22:39:12.704  INFO 9476 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-11-19 22:39:12.880  INFO 9476 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-11-19 22:39:13.401  INFO 9476 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-11-19 22:39:13.676  INFO 9476 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2019-11-19 22:39:13.685  INFO 9476 --- [           main] i.j.s.CourseApiDataApplication           : Started CourseApiDataApplication in 15.081 seconds (JVM running for 15.919)
TopicService类:用于对主题实体执行crud操作

package io.javabrains.springbootstarter.Topic;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Service;

@Service
public class TopicService {

    private TopicRepository topicRepository;


  public List<Topic> getAllTopics(){

      List<Topic> lst = new ArrayList<>();
      topicRepository.findAll().forEach(lst:: add);
      return lst;
  }

  public Topic getTopic(int id) {

       return topicRepository.findOne(id);


      //return topicList.stream().filter(t -> t.getName().equals(name)).findFirst().get();
}

  public void addTopic(Topic topic) {

     topicRepository.save(topic);

      //topicList.add(topic);
  }

  public void updateTopic(Topic topic , int id) {


      topicRepository.save(topic);//we do not need another method for update , save method can do both insert and update . it checks firsst
      // whether id of topic object is already there in table if it finds the id , it updats it otherwise insert

      //topicList.set(id-1  , topic);
}

public void deleteTopic(int id) {

    /*for(int i=1; i<=topicList.size(); i++) {

        topicList.removeIf(t->t.getId()==id);
    }*/

    topicRepository.delete(id);
}

}

您错过的一件事是数据库连接URL。 将其添加到application.properties文件中


spring.datasource.url=jdbc:derby:mydb;create=true

这里可以应用的解决方案是将以下参数添加到
应用程序.properties
文件中

spring.datasource.initialization-mode=always

你能粘贴完整的application.properties文件吗?我在applicaton.properties文件中有这两行。嗨,谢谢Jeyam的回答。我在application.properties文件中使用了url,但仍然得到相同的错误:(
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>io.javarbrains</groupId>
    <artifactId>Course-api-data</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Course-api-data</name>
    <description>Demo project for Spring Boot api with data</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.1.4.Final</version>
</dependency>
 -->

<!-- <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.3.Final</version>
</dependency>

         -->

         <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
</dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.datasource.initialization-mode=always