用户登录
用户注册

分享至

hibernate.xml配置

  • 作者: 小狗爱吃鱼
  • 来源: 51数据库
  • 2021-01-01
hibernate的映射有2种方式
xml和 annotaion

xml的好处是:它是配置!是脱离代码之外的东西,可以允许你在你的项目部署之后,再去做细微修改(如果你的项目做得有弹性的话)
xml的缺点:繁琐!写了一大堆,发现节点的字数比真实数据的字数多太多了...浪费!

annotation的好处:维护的页面少!不用写项目的时候在N的文档直接,切来切去的!而且非常简练,比xml少非常多!
annotation的坏处:和程序纠缠在了一起...

推荐用法:
在项目开发阶段用annotation做配置,这样可以大大提高项目的效率

等到项目开发,测试完成之后,再重新写回xml然后再去部署



  用xml比较标准,而且清楚



  xml



  <p>hibernate.dialect net.sf.hibernate.dialect.mysqldialect<br>hibernate.connection.driver_class org.gjt.mm.mysql.driver<br>hibernate.connection.driver_class com.mysql.jdbc.driver<br>hibernate.connection.url jdbc:mysql://localhost:3306/test<br>hibernate.connection.username root<br>hibernate.connection.password </p>  <p>&nbsp;</p>  <p>&lt;?xml version='1.0' encoding='utf-8'?&gt;<br>&lt;!doctype hibernate-configuration<br>&nbsp;&nbsp;&nbsp; public "-//hibernate/hibernate configuration dtd//en"<br>&quot; <a 
软件
前端设计
程序设计
Java相关