我对JBoss 7.1和Liquibase有问题。
我把我的基础存储在内存中,但在我重新启动服务器后,数据库并没有重新启动,根据创建已经存在的表,我出现了错误。
我的变更日志:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="1" author="dobiesl">
<createTable tableName="ksiazka">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false" />
</column>
<column name="tytul" type="varchar(50)">
<constraints nullable="false" />
</column>
<column name="rok_wydania" type="int">
<constraints nullable="false" />
</column>
<column name="dostepnosc" type="int">
<constraints nullable="false" />
</column>
</createTable>
</changeSet>
<changeSet id="2" author="dobiesl">
<insert tableName="ksiazka">
<column name="id" type="int" value="1">
</column>
<column name="tytul" type="varchar(50)" value="Pan Tadeusz">
</column>
<column name="rok_wydania" type="int" value="1999">
</column>
<column name="dostepnosc" type="int" value="1">
</column>
</insert>
<insert tableName="ksiazka">
<column name="id" type="int" value="2">
</column>
<column name="tytul" type="varchar(50)" value="W pustyni i w puszczy">
</column>
<column name="rok_wydania" type="int" value="1999">
</column>
<column name="dostepnosc" type="int" value="1">
</column>
</insert>
<insert tableName="ksiazka">
<column name="id" type="int" value="3">
</column>
<column name="tytul" type="varchar(50)" value="Ogniem i mieczem">
</column>
<column name="rok_wydania" type="int" value="2001">
</column>
<column name="dostepnosc" type="int" value="1">
</column>
</insert>
<insert tableName="ksiazka">
<column name="id" type="int" value="4">
</column>
<column name="tytul" type="varchar(50)" value="Pan Wolodyjowski">
</column>
<column name="rok_wydania" type="int" value="1975">
</column>
<column name="dostepnosc" type="int" value="1">
</column>
</insert>
<insert tableName="ksiazka">
<column name="id" type="int" value="5">
</column>
<column name="tytul" type="varchar(50)" value="Potop">
</column>
<column name="rok_wydania" type="int" value="1998">
</column>
<column name="dostepnosc" type="int" value="0">
</column>
</insert>
</changeSet>
<changeSet id="3" author="dobiesl">
<createTable tableName="autor">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false" />
</column>
<column name="imie" type="varchar(50)">
<constraints nullable="false" />
</column>
<column name="nazwisko" type="varchar(50)">
<constraints nullable="false" />
</column>
</createTable>
</changeSet>
<changeSet id="4" author="dobiesl">
<insert tableName="autor">
<column name="id" type="int" value="1">
</column>
<column name="imie" type="varchar(50)" value="Adam">
</column>
<column name="nazwisko" type="varchar(50)" value="Mickiewicz">
</column>
</insert>
<insert tableName="autor">
<column name="id" type="int" value="2">
</column>
<column name="imie" type="varchar(50)" value="Henryk">
</column>
<column name="nazwisko" type="varchar(50)" value="Sienkiewicz">
</column>
</insert>
<insert tableName="autor">
<column name="id" type="int" value="3">
</column>
<column name="imie" type="varchar(50)" value="Stefan">
</column>
<column name="nazwisko" type="varchar(50)" value="Zeromski">
</column>
</insert>
</changeSet>
<changeSet id="5" author="dobiesl">
<createTable tableName="ksiazka_autor">
<column name="aid" type="int">
<constraints nullable="false" />
</column>
<column name="kid" type="int">
<constraints nullable="false" />
</column>
</createTable>
</changeSet>
<changeSet id="6" author="dobiesl">
<insert tableName="ksiazka_autor">
<column name="aid" type="int" value="1">
</column>
<column name="kid" type="int" value="1">
</column>
</insert>
<insert tableName="ksiazka_autor">
<column name="aid" type="int" value="2">
</column>
<column name="kid" type="int" value="2">
</column>
</insert>
<insert tableName="ksiazka_autor">
<column name="aid" type="int" value="2">
</column>
<column name="kid" type="int" value="3">
</column>
</insert>
<insert tableName="ksiazka_autor">
<column name="aid" type="int" value="2">
</column>
<column name="kid" type="int" value="4">
</column>
</insert>
<insert tableName="ksiazka_autor">
<column name="aid" type="int" value="2">
</column>
<column name="kid" type="int" value="5">
</column>
</insert>
</changeSet>
</databaseChangeLog>
持久性:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="pl.biblioteka.baza" >
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- the JNDI data source -->
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<properties>
<!-- if this is true, hibernate will print (to stdout) the SQL it executes,
so you can check it to ensure it's not doing anything crazy -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<!-- since most database servers have slightly different versions of the
SQL, Hibernate needs you to choose a dialect so it knows the subtleties of
talking to that server -->
<!--<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"
/> -->
<!-- this tell Hibernate to update the DDL when it starts, very useful
for development, dangerous in production -->
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
jboss配置:
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
为什么我会出现这种错误?
<property name="hibernate.hbm2ddl.auto" value="update" />
这就是问题所在。Hibernate在liquibase之前就已经从实体中创建了表。