'greeter'是WildFly 8中的一个快速启动项目,作为教程演示基本hibernate数据库和JPA功能。在这个项目中,我不明白何时以及如何在H2数据库中创建“用户”数据库。这些是用于创建和设置数据库的两个相关文件:
<persistence version="2.0"
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_2_0.xsd">
<persistence-unit name="primary">
<!-- If you are running in a production environment, add a managed
data source, this example data source is just for development and testing! -->
<!-- The datasource is deployed as WEB-INF/greeter-quickstart-ds.xml,
you can find it in the source at src/main/webapp/WEB-INF/greeter-quickstart-ds.xml -->
<jta-data-source>java:jboss/datasources/GreeterQuickstartDS</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence><datasources xmlns="http://www.jboss.org/ironjacamar/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<!-- The datasource is bound into JNDI at this location. We reference
this in META-INF/persistence.xml -->
<datasource jndi-name="java:jboss/datasources/GreeterQuickstartDS"
pool-name="greeter-quickstart" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
</datasources>INSERT INTO USERS (ID, USERNAME, FIRSTNAME, LASTNAME) VALUES (-1, 'jdoe', 'John', 'Doe');
INSERT INTO USERS (ID, USERNAME, FIRSTNAME, LASTNAME) VALUES (-2, 'emuster', 'Erika', 'Mustermann');默认情况下,H2数据库系统不附带由演示程序使用的用户数据库。那么,如何在这个演示项目中创建“用户”呢?谢谢。
发布于 2014-11-02 05:41:32
由于persistence.xml中的下列设置,在运行该项目时,用户数据库将自动重新生成
<property name="hibernate.hbm2ddl.auto" value="create-drop" />发布于 2015-03-05 11:38:04
数据库是由Hibernate在部署时设置的。为了构建数据库模式,Hibernate扫描所有相关文件,不仅是XML文件,还包括类,以获取它所需的信息,这就是表用户的来源。
下面是greeter快速启动示例中负责用户表的确切代码:
@Entity
// User is a keyword in some SQL dialects!
@Table(name="Users")
public class User {
... etc.因此,为了避免与您选择的数据库管理系统发生冲突,他们将其命名为用户。
https://stackoverflow.com/questions/26696275
复制相似问题