Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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 为什么当我给mvn干净的包时,我得到这个错误:找不到表?_Java_Spring - Fatal编程技术网

Java 为什么当我给mvn干净的包时,我得到这个错误:找不到表?

Java 为什么当我给mvn干净的包时,我得到这个错误:找不到表?,java,spring,Java,Spring,我在用户之间建立友谊,用户可以有任何朋友,有朋友列表, 我正在使用swagger发出请求,但是我得到了错误500,带有空值,我不知道为什么 这个mis控制器,我使用请求post @CrossOrigin(origins = "http://localhost:4200", maxAge = 3600) @RestController @RequestMapping({"/user"}) public class UserController { @Autowired UserS

我在用户之间建立友谊,用户可以有任何朋友,有朋友列表, 我正在使用swagger发出请求,但是我得到了错误500,带有空值,我不知道为什么

这个mis控制器,我使用请求post

@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600)
@RestController
@RequestMapping({"/user"})
public class UserController {

    @Autowired
    UserServiceImpl userServiceImpl;
    static Logger log = Logger.getLogger(UserController.class.getName());

    @PostMapping("/create")
    public ResponseEntity<User> createUser(@RequestBody User user) {
        log.info("CREATE");
        return new ResponseEntity<User>(userServiceImpl.createUser(user), HttpStatus.OK);
    }


    @PostMapping("/addFriend")
    public ResponseEntity<User> addFriend(@RequestBody Friendship friendship) {
        log.info("addFriend");
        return new ResponseEntity<User>(userServiceImpl.createLinkWithFriends(friendship), HttpStatus.OK);
    }

    @GetMapping("/getUsers")
    public ResponseEntity<List<User>> getUsers() {
        log.info("getUser");
        return new ResponseEntity<>(userServiceImpl.getUsers(), HttpStatus.OK);
    }

    @GetMapping("/showFriends/{id}")
    public ResponseEntity<List<User>> getUsers(@PathVariable("id")  int id) {
        log.info("showFriends"+id);
        return new ResponseEntity<>(userServiceImpl.getUsers(), HttpStatus.OK);
    }

}
我得到这个错误,为什么我没有找到表友谊?此错误是在我制作
mvn清洁包时发生的

   2019-05-03 23:54:59.925  INFO 20200 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2019-05-03 23:54:59.925  INFO 20200 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2019-05-03 23:54:59.931  INFO 20200 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2019-05-03 23:54:59.979  INFO 20200 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-05-03 23:55:00.132  INFO 20200 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-05-03 23:55:01.094  INFO 20200 --- [           main] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2019-05-03 23:55:01.132  INFO 20200 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: friendship
2019-05-03 23:55:01.133  INFO 20200 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: friendship
2019-05-03 23:55:01.136  WARN 20200 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.sp
ringframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/Hibern
ateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFac
tory
2019-05-03 23:55:01.152  INFO 20200 --- [           main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-05-03 23:55:01.184 ERROR 20200 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/
HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate Sess
ionFactory
文件application.properties包含以下内容:

spring.h2.console.enabled=true
spring.h2.console.path=/h2_console
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create

在我看来,插入时为空的是连接表的ID(
Friendly.ID\u friend
),这似乎是正确的。在插入过程中,数据库应该将该null转换为实际ID,但这不会发生并导致异常


仔细检查
友谊
表是如何设置的,特别是
id\u friend
列是自动递增还是具有类似的触发器。

在我看来,插入时为空的是连接表的id(
友谊.id\u friend
)。在插入过程中,数据库应该将该null转换为实际ID,但这不会发生并导致异常


仔细检查
友谊
表是如何设置的,特别是如果
id\u friend
列是自动递增的或具有类似的触发器。

id\u friend是自动的,请参阅@GeneratedValue(strategy=GenerationType.Auto)private long idFriend;是的,它在代码中是自动的,但在数据库中是自动的吗?两者必须匹配,但有时不匹配,因此建议重新检查实际的数据库设置。SQL异常表明数据库设置不正确。我使用了bd h2,我如何看待此bd?您可以启用h2控制台:我有一个与id有关的新问题。\u friend是auto,请参阅@GeneratedValue(strategy=GenerationType.auto)private long idFriend;是的,它在代码中是自动的,但在数据库中是自动的吗?两者必须匹配,但有时不匹配,因此建议重新检查实际的数据库设置。SQL异常表明数据库设置不正确。我使用了bd h2,我如何看待此bd?您可以启用h2控制台:我有新的相关问题
@Entity
@Table(name = "Friendship")
public class Friendship implements Serializable {

    private static final long serialVersionUID = -3009157732242241606L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    //@GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id_friend;

    @ManyToOne
    private User owner;

    @ManyToOne
    private User friend;

    public Friendship() {

    }

    public long getId_friend() {
        return id_friend;
    }

    public void setId_friend(long id_friend) {
        this.id_friend = id_friend;
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    public User getFriend() {
        return friend;
    }

    public void setFriend(User friend) {
        this.friend = friend;
    }
}
   2019-05-03 23:54:59.925  INFO 20200 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2019-05-03 23:54:59.925  INFO 20200 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2019-05-03 23:54:59.931  INFO 20200 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2019-05-03 23:54:59.979  INFO 20200 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-05-03 23:55:00.132  INFO 20200 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-05-03 23:55:01.094  INFO 20200 --- [           main] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2019-05-03 23:55:01.132  INFO 20200 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: friendship
2019-05-03 23:55:01.133  INFO 20200 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: friendship
2019-05-03 23:55:01.136  WARN 20200 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.sp
ringframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/Hibern
ateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFac
tory
2019-05-03 23:55:01.152  INFO 20200 --- [           main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-05-03 23:55:01.184 ERROR 20200 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/
HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate Sess
ionFactory
spring.h2.console.enabled=true
spring.h2.console.path=/h2_console
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create