Question

Where(path) should I put the .hbm.xml and .cfg.xml in hibernate

I am using Netbeans IDE

Was it helpful?

Solution

I remember when I first used Hibernate and wanted to learn, I used the following NetBeans tutorial. It taught me to put in the root directory (i.e. not in a specific package). The reason for that was because it is the easiest option for those new to Hibernate and who want to learn how to use Hibernate effectively. However, once you have gained a little bit more experience, it doesn't really matter where you put it, as long as it is logical and clear.

However, for the sake of clarity, it is best to follow the NetBeans tutorial's logic of putting it within the default package.

Another note, if you are new to Hibernate, it may be worth sticking to the annotations, rather than the XML files. The annotations are much clearer and they are seeming to become much more powerful and popular.

OTHER TIPS

You can put the .cfg file in the src package and in .cfg file you can specify the hbm file path. Sample configuration in cfg file :

<hibernate-configuration>
<session-factory>
  <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.password">password</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="show_sql">true</property>
  <mapping resource="com/modle/Person.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top