【发布时间】:2021-01-04 14:53:24
【问题描述】:
我很困惑,因为如果我不使用 hibernate.cfg.xml 文件,我无法让 DDL 生成工作。
如何在没有 XML 配置文件的代码中配置会话工厂时休眠以调用 DDL 生成?我在这里缺少什么?
我的会话工厂通过代码生成,其中 DDL 不起作用。
Configuration configuration = new Configuration();
configuration
.setProperty("hibernate.connection.driver_class", "org.sqlite.JDBC")
.setProperty("hibernate.connection.url", "jdbc:sqlite:mydb.db")
.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLiteDialect")
.setProperty("hibernate.show_sql", "true")
.setProperty("hibernate.format_sql", "true")
.setProperty("connection.username", "")
.setProperty("connection.password", "")
.setProperty("hibernate.hdm2ddl.auto", "update");
configuration.addAnnotatedClass(Bill.class);
this.factory = configuration.buildSessionFactory();
通过 hibernate.xml 生成会话工厂。
Configuration configuration = new Configuration();
configuration.configure();
hibernate.cfg.xml(没有 XML 标头)
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="dialect">org.hibernate.dialect.SQLiteDialect</property>
<property name="connection.driver_class">org.sqlite.JDBC</property>
<property name="connection.url">jdbc:sqlite:rechnungen.db</property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="entity.Bill"/>
</session-factory>
</hibernate-configuration>
【问题讨论】:
-
你用的是什么休眠版本?
-
版本 5.4.26.Final
标签: java hibernate hibernate-mapping