我的Spring+Hibernate学习笔记(一)

关于org.hibernate.tool.hbm2ddl.SchemExport
最近研究Spring+Hibernate,打算做基于内存数据库的web项目,用到HSQLDB。
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">create</property>	
</session-factory>
</hibernate-configuration>

系统启动时会提示自动导入classpath跟路径下的import.sql脚本构建数据库

[2008-08-21 10:13:34,312][INFO,tool.hbm2ddl.SchemaExport] Running hbm2ddl schema export
[2008-08-21 10:13:34,328][INFO,tool.hbm2ddl.SchemaExport] exporting generated schema to database
[2008-08-21 10:13:34,328][INFO,tool.hbm2ddl.SchemaExport] Executing import script: /import.sql
[2008-08-21 10:13:34,328][DEBUG,tool.hbm2ddl.SchemaExport] DROP TABLE IF EXISTS hibernate_unique_key
[2008-08-21 10:13:34,328][DEBUG,tool.hbm2ddl.SchemaExport] CREATE TABLE hibernate_unique_key(next_hi int GENERATED BY DEFAULT AS IDENTITY (start with 1),PRIMARY KEY (next_hi))
[2008-08-21 10:13:34,328][DEBUG,tool.hbm2ddl.SchemaExport] INSERT INTO hibernate_unique_key(next_hi) VALUES(1)
[2008-08-21 10:13:34,328][INFO,tool.hbm2ddl.SchemaExport] schema export complete

对应脚本如下
--HSQLDB HQL 任务 org.hibernate.tool.hbm2ddl.SchemaExport Executing import script: /import.sql
--该操作语句解析是按行进行的,所以HQL语句要按行录入。

--清理表hibernate_unique_key
DROP TABLE IF EXISTS hibernate_unique_key;
--构建表hibernate_unique_key
CREATE TABLE hibernate_unique_key(next_hi int GENERATED BY DEFAULT AS IDENTITY (start with 1),PRIMARY KEY (next_hi));
--插入默认值
INSERT INTO hibernate_unique_key(next_hi) VALUES(1);

如此就可以构建一个内存表hibernate_unique_key,这个表是我用来给其他表生成高低位主键用的基础表。

你可能感兴趣的:(spring,sql,Hibernate,脚本,HSQLDB)