where(path)我应该将.hbm.xml和.cfg.xml放在hibernate中

时间:2014-03-01 12:21:27

标签: hibernate

我应该将.hbm.xml和.cfg.xml放在hibernate中的哪个(路径)

我正在使用Netbeans IDE

2 个答案:

答案 0 :(得分:1)

我记得当我第一次使用Hibernate并想学习时,我使用了以下NetBeans tutorial。它教会我放入根目录(即不在特定的包中)。原因是因为对于那些刚接触Hibernate并希望学习如何有效使用Hibernate的人来说,它是最简单的选择。然而,一旦你获得了更多的经验,只要它合乎逻辑且清晰,你在哪里放置它并不重要。

但是,为了清楚起见,最好遵循NetBeans教程将其置于默认包中的逻辑。

另外需要注意的是,如果您是Hibernate的新手,可能值得注意注释,而不是XML文件。注释更加清晰,它们似乎变得更加强大和受欢迎。

答案 1 :(得分:0)

您可以将.cfg文件放在src包和.cfg文件中,您可以指定hbm文件路径。 cfg文件中的示例配置:

<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>