I'm new to java and hibernate framework, can you please explain to me if I have to make a Hibernate cfg file for every table I have or only this is enough. At the moment I have this and it takes care of a person table, now if I want to also work with a new table (exam in my case) do I need to write a new file and change the 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>
</session-factory>
</hibernate-configuration>
You just need only ONE cfg file, if you need to add a new table just post it as
<mapping class="com.scheduler.backend.model.NEW_MODEL"></mapping>
So the file be like this:
<?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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.