简体   繁体   English

Spring Boot无法从HSQLDB启动

[英]Spring boot fails to start with HSQLDB

I am trying to create a simple spring boot app which would connect to HSQLDB and work with User table, however I am getting this when trying to start it. 我正在尝试创建一个简单的spring boot应用程序,该应用程序将连接到HSQLDB并使用User表,但是尝试启动它时却遇到了这个问题。

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 SessionFactory

With the whole console output here: http://pastebin.com/7HminjFL 此处带有整个控制台的输出: http : //pastebin.com/7HminjFL

My files ares: 我的档案是:

Application.java Application.java

@Configuration
@SpringBootApplication
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "hello")
@ComponentScan(basePackages = "hello")
@PropertySource({"classpath:application.properties"})

public class Application {

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

Account.java Account.java

@Entity
@Table(name = "User", schema = "PUBLIC")
public class Account implements Serializable {

    @Id
    private Long id;

    @Column(name = "Login", nullable = false)
    private String login;

    @Column(name = "Password", nullable = false)
    private String password;


    protected Account() {
        // no-args constructor required by JPA spec
        // this one is protected since it shouldn't be used directly
    }

    public Account(String login, String password) {
        this.login = login;
        this.password = password;
    }

    public String getLogin() {
        return login;
    }

    public String getPassword() {
        return password;
    }

    public void setLogin(String login) {
        this.login = login;
        return;
    }

    public void setPassword(String password) {
        this.password = password;
        return;
    }
}

AccountRepository.java AccountRepository.java

public interface AccountRepository extends JpaRepository<Account, Long> {

    Long countByLogin(String login);
}

application.properties application.properties

spring.datasource.url=jdbc:hsqldb:file:C:\DB\TestDB
spring.datasource.username=SA
spring.datasource.password=
spring.datasource.driver-class-name=org.hsqldb.jdbcDriver

Your stack trace gives some direction to the problem. 您的堆栈跟踪为该问题提供了一些指导。

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: hello.Account 原因:org.hibernate.AnnotationException:未为实体指定标识符:hello.Account

Switch your @Id annotation import on Account class. Account类上切换@Id注释导入。

Probably you are using: import org.springframework.data.annotation.Id . 可能您正在使用:import org.springframework.data.annotation.Id Exchange for import javax.persistence.Id and try to start your application again; 交换import javax.persistence.Id并尝试再次启动您的应用程序;


By the way, @SpringBootApplication is a convenient way to start your SpringBoot application. 顺便说一句, @SpringBootApplication SpringBootApplication是启动SpringBoot应用程序的便捷方法。 If you use it, you don't need to add @Configuration , @EnableAutoConfiguration and @ComponentScan . 如果使用它,则无需添加@Configuration Configuration, @ComponentScan EnableAutoConfiguration和@ComponentScan

@SpringBootApplication @SpringBootApplication

Indicates a {@link Configuration configuration} class that declares one or more {@link Bean @Bean} methods and also triggers {@link EnableAutoConfiguration auto-configuration} and {@link ComponentScan component scanning}. 表示一个{@link Configuration configuration}类,该类声明一个或多个{@link Bean @Bean}方法,并且还触发{@link EnableAutoConfiguration自动配置}和{@link ComponentScan组件扫描}。

This is a convenience annotation that is equivalent to declaring {@code @Configuration}, {@code @EnableAutoConfiguration} and {@code @ComponentScan}. 这是一个方便注释,等效于声明{@code @Configuration},{@ code @EnableAutoConfiguration}和{@code @ComponentScan}。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM