我是java和hibernate框架的新手,你能向我解释一下,如果我必须为我拥有的每个表都创建一个Hibernate cfg文件,还是只需要这样就足够了。现在我有了一个person表,现在如果我还想使用一个新表(在我的例子中是exam),我是否需要编写一个新文件并更改映射?
<?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3310/scheduler</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">blanked-out-as-this-is-s3cr3t</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="com.scheduler.backend.model.Person"></mapping>
</session-factory>
</hibernate-configuration>发布于 2019-12-22 19:58:02
您只需要一个 cfg文件,如果您需要添加一个新表,只需将其发布为
<mapping class="com.scheduler.backend.model.NEW_MODEL"></mapping>所以这个文件是这样的:
<?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3310/scheduler</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">blanked-out-as-this-is-s3cr3t</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="com.scheduler.backend.model.Person"></mapping>
<mapping class="com.scheduler.backend.model.NEW_ONE"></mapping>
<mapping class="com.scheduler.backend.model.NEW_ONE"></mapping>
</session-factory>
</hibernate-configuration>https://stackoverflow.com/questions/59443890
复制相似问题