Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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
如何使用注释在Spring JPA中定义HSQ DB属性_Spring_Jpa_Annotations_Hsqldb - Fatal编程技术网

如何使用注释在Spring JPA中定义HSQ DB属性

如何使用注释在Spring JPA中定义HSQ DB属性,spring,jpa,annotations,hsqldb,Spring,Jpa,Annotations,Hsqldb,我使用RunMangerSwing将HSQLDB作为Im内存运行。我必须使用注释从SpringJPA存储库连接HSQLDB服务器。 我的存储库类 @RepositoryRestResource public interface Vehicle extends JpaRepository<Vehicle , BigInteger>{ public List<Vehicle > findAll(Sort sort); } 服务方式: @服务 任何人都可以使用注释帮

我使用RunMangerSwing将HSQLDB作为Im内存运行。我必须使用注释从SpringJPA存储库连接HSQLDB服务器。 我的存储库类

@RepositoryRestResource
public interface Vehicle extends JpaRepository<Vehicle , BigInteger>{
    public List<Vehicle > findAll(Sort sort);

}
服务方式: @服务


任何人都可以使用注释帮助实现使用HSQL DB的Spring JPA连接。

我假设您不使用Spring boot:

您需要@Configuration类——它基本上是一种用@EnableJpaRepositories在java中配置spring应用程序的新方法,它将spring数据转换为jpa/spring数据rest。您还必须指定实体管理器、事务管理器和数据源bean。示例如下:

@Configuration
@EnableJpaRepositories("your.package.with.repositories")
public class DBConfig{
 @Bean
public JpaTransactionManager transactionManager() {
    JpaTransactionManager transactionManager = new JpaTransactionManager();

    transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());

    return transactionManager;
}

@Bean
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    DBConfigurationCommon.configureDB(dataSource, your_jdbc_url_here, db_username_here, db_password_here);
    return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();

    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());

    //you may need to define new Properties(); here with hibernate dialect and add it to entity manager factory
    entityManagerFactoryBean.setPackagesToScan("your_package_with_domain_classes_here");

    return entityManagerFactoryBean;
}
}
@Configuration
@EnableJpaRepositories("your.package.with.repositories")
public class DBConfig{
 @Bean
public JpaTransactionManager transactionManager() {
    JpaTransactionManager transactionManager = new JpaTransactionManager();

    transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());

    return transactionManager;
}

@Bean
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    DBConfigurationCommon.configureDB(dataSource, your_jdbc_url_here, db_username_here, db_password_here);
    return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();

    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());

    //you may need to define new Properties(); here with hibernate dialect and add it to entity manager factory
    entityManagerFactoryBean.setPackagesToScan("your_package_with_domain_classes_here");

    return entityManagerFactoryBean;
}
}