문제

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

I am using Netbeans IDE

도움이 되었습니까?

해결책

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.

다른 팁

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top