我在程序中使用annotation. 但是为什么运行的时候还是会提示缺少hbm文件呢?使用annotation不是就可以不需要hbm文件吗?

解决方案 »

  1.   

    有没有彻底使用spring来管理hibernate的设置
      

  2.   

    只是单单使用Hibernate来做实验.并没有用其他的框架
      

  3.   

    把你的hibernate.cfg.xml 贴出来看看。在这个文件里面要配置实体类。
      

  4.   

    楼上+1不太清楚,hibernate可能不会像spring那样自动扫描annotation标记的实体类,仍需要简单的配置
    <?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">
     
     <!-- Generated by MyEclipse Hibernate Tools.                   -->
     <hibernate-configuration>
     
      <session-factory>
       <property name="dialect">
        org.hibernate.dialect.MySQLDialect
       </property>
       <property name="connection.url">
        jdbc:mysql://localhost:3307/users
       </property>
       <property name="connection.username">root</property>
       <property name="connection.password">root</property>
       <property name="connection.driver_class">
        com.mysql.jdbc.Driver
       </property>
       <property name="myeclipse.connection.profile">
        mysqlusers
       </property>
       <property name="format_sql">true</property>
       <property name="show_sql">true</property>
       <property name="current_session_context_class">thread</property>
       <mapping class="com.b510.examples.Product" />
       <mapping class="com.b510.examples.Category" />

     
      </session-factory>
     
     </hibernate-configuration>楼主不妨试试验证一下http://www.cnblogs.com/hongten/archive/2011/07/20/2111773.html