当前位置: 首页 > 面试题库 >

在HSQLDB中创建架构的启动脚本

岳承悦
2023-03-14
问题内容

我正在尝试使用内存数据库来模拟Teradata数据库。在构建表之前,我需要创建一个架构,但是,这很适合我。

我正在使用Spring,并且与进行了大量数据库交互import.sql,但是,这在Hibernate创建所有表之后执行。我试图使用.scriptHSQLDB应该读取的html" target="_blank">文件,但是我认为当您使用内存数据库无法正常工作时。我将文件移动了一点,似乎什么也没打。

任何人都知道如何在启动时为内存中的HSQLDB数据库创建架构吗?


问题答案:

如果您以这种方式运行脚本…

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">


<jdbc:embedded-database id="dataSource" type="H2" >
    <jdbc:script location="classpath:my.sql" />     
</jdbc:embedded-database>

…然后在Hibernate进行初始化工作之前执行它。

我再次测试了它,特别是对您来说。它在Hibernate创建表之前运行。请参阅以下日志( 在前三行中运行脚本,在最后三行中运行Hibernate ):

2011-11-01 19:10:08,380 [main] INFO  org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory - Creating embedded database 'dataSource'
2011-11-01 19:10:08,583 [main] INFO  org.springframework.jdbc.datasource.init.ResourceDatabasePopulator - Executing SQL script from class path resource [my.sql]
2011-11-01 19:10:08,683 [main] INFO  org.springframework.jdbc.datasource.init.ResourceDatabasePopulator - Done executing SQL script from class path resource [my.sql] in 100 ms.
2011-11-01 19:10:08,683 [main] INFO  org.springframework.context.support.GenericApplicationContext - Bean 'dataSource' of type [class org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2011-11-01 19:10:08,683 [main] INFO  org.springframework.context.support.GenericApplicationContext - Bean 'dataSource' of type [class org.springframework.jdbc.datasource.SimpleDriverDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2011-11-01 19:10:08,700 [main] INFO  org.springframework.context.support.GenericApplicationContext - Bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#35712651' of type [class org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2011-11-01 19:10:08,717 [main] INFO  org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'testH2DbPersistenceUnit'
2011-11-01 19:10:08,854 [main] INFO  org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
2011-11-01 19:10:08,859 [main] INFO  org.hibernate.cfg.Environment - Hibernate 3.6.7.Final
2011-11-01 19:10:08,861 [main] INFO  org.hibernate.cfg.Environment - hibernate.properties not found
...
2011-11-01 19:10:10,313 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaUpdate - Running hbm2ddl schema update
2011-11-01 19:10:10,313 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaUpdate - fetching database metadata
2011-11-01 19:10:10,315 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaUpdate - updating schema


 类似资料:
  • 当Spring启动加载时,我需要在Postgres中创建一个新模式。因此,它应该检查模式是否不存在,然后创建一个新模式。我正在使用application.properties进行数据库配置。 Postgres使用的默认模式是公共的,我需要更改使我自己的模式,我将在env中定义。

  • 问题内容: 我使用 hsqldb 运行需要数据库访问权限的单元测试。 目前,当我想为特定测试创建表时,我具有以下代码: 该方法检索在上下文中定义的DataSource : 现在,我想从一个SQL脚本创建表(当然,此脚本将包含多个表创建): 在HSQLDB文档中,我可以要求他在启动时运行脚本。但是,它不符合我的要求,因为我想在运行时运行脚本。 当然,我可以自己读取文件,并且对于每个SQL语句,我都运

  • 问题内容: 我无法启动启动时自动启动数据库架构的Spring Boot。 这是我的application.properties: 这是我的Application.java: 这是一个示例实体: 有什么想法我做错了吗? 问题答案: 有几种可能的原因: 您的实体类位于与之相对的同一个子包中,或者在一个子包中,如果没有,则您的spring应用不会看到它们,因此不会在db中创建任何内容 检查您的配置,似乎

  • 我使用spring-boot-starter-data-solr,并希望利用Spring Data Solr的schmea cration支持,如文档中所述: 每当刷新应用程序上下文时,自动架构填充都会检查您的域类型,并根据属性配置将新字段填充到索引中。这要求 solr 在无架构模式下运行。 但是,我无法实现这一目标。据我所知,Spring启动器不会在@EnableSolrRepositories

  • 问题内容: 我有一个可以在MongoDB和mongoose上的node.js上运行的应用程序。我的应用程序只是发送/删除/编辑表单数据,为此,我有这样的猫鼬模型: 而且效果很好! 现在,我想向表单添加一个功能,以便用户可以添加一个或多个字段来表单并在其中输入文本并发布。在客户端上创建动态功能没问题,但是我知道我的mongoose.model必须正确构造。我的问题是:如何将变量值(动态创建的表单数据

  • 我有一个使用Spring Boot的中等规模项目,我正在尝试使用嵌入式H2创建我的第一个DataJpaTest,但我遇到了以下例外: 我已经尝试了这一点,并使用了一个模式。sql,还有这个和使用测试。测试/资源中的属性,以及其他答案。但什么都没用。我真的很困惑;这是我第一次在Spring Boot中遇到无法解决的问题。 我的实体类定义为: 关于如何强制Hibernate在H2中创建模式的任何建议?