简体   繁体   中英

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.

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

My files ares:

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

@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

public interface AccountRepository extends JpaRepository<Account, Long> {

    Long countByLogin(String login);
}

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

Switch your @Id annotation import on Account class.

Probably you are using: import org.springframework.data.annotation.Id . Exchange for import javax.persistence.Id and try to start your application again;


By the way, @SpringBootApplication is a convenient way to start your SpringBoot application. If you use it, you don't need to add @Configuration , @EnableAutoConfiguration and @ComponentScan .

@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}.

This is a convenience annotation that is equivalent to declaring {@code @Configuration}, {@code @EnableAutoConfiguration} and {@code @ComponentScan}.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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