<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.SQLServerDialect
                </prop>
                <prop key="hibernate.connection.autocommit">true</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="connection.useUnicode">true</prop>
                <prop key="connection.characterEncoding">utf-8</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.order_updates">true</prop>
                <prop key="hibernate.connection.release_mode">
                    after_transaction
                </prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>
       <property name="annotatedClasses">
            <list>
             <value>entity.User</value>
            </list>
        </property>  
    </bean>
public static void main(String[] args) { Configuration config = new Configuration().configure(); SchemaExport export = new SchemaExport(config); export.create(true, true);
}
beans.xml和创建表的类如上
为什么这时候报错是Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
冰天雪地全裸跪求大大们给点答案

解决方案 »

  1.   

    hibernate.cfg.xml
    这个应该是写hibernate与数据库连接的吧,你有吗?每个类也得有个配置文件写相关属性
      

  2.   

    我用的是spring整合hibernate
    就不用那个文件了
    内容都在bean.xml里面呢
      

  3.   

    你用spring 配置hibernate 但是也得知道连数据库的配置信息啊、驱动、账号、密码、数据库名、url、
    在你bean.xml里根本没发现这些啊、
    <bean id="dataSource"
              class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
            <property name="driverClass">
                <value>com.mysql.jdbc.Driver</value>
            </property>
            <property name="jdbcUrl">
                <value>jdbc:mysql://localhost:3306/XXXXX?useUnicode=true&characterEncoding=UTF-8</value>
            </property>
            <property name="user">
                <value>root</value>
            </property>
            <property name="password">
                <value>123456</value>
            </property>
            
        </bean>
      

  4.   

    第一种方法:hibernate.cfg.xml放到src目录下
    第二种方法,将包含hibernate.cfg.xml的目录,加到工程的classpath下。
      

  5.   

    看一下apache发布目录是否有hibernate.cfg.xml,如果没有,eclipse重新发布一下
      

  6.   

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
    <property name="url" value="jdbc:sqlserver://localhost:1433;databasename=mytest1"></property>
    <property name="username" value="sa"></property>
    <property name="password" value="sa"></property>
    <property name="maxActive" value="100"></property>
    <property name="maxIdle" value="30"></property>
    <property name="maxWait" value="500"></property>
    </bean>
    你要配置一个 dataSource 啊!!
      

  7.   

    赞同3楼的 你的hibernate配置信息不完整