解决方案 »

  1.   

    配置初始化失败, sessionfactory 配置错了
      

  2.   

    applicationContext.xml<?xml version="1.0" encoding="UTF-8"?>
    <beans
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/aop 
                http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                http://www.springframework.org/schema/tx 
                http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                http://www.springframework.org/schema/context 
                http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- 开启注解处理器 -->
        <context:annotation-config/>
        
    <!-- 定义使用C3P0连接池的数据源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <!-- 指定连接数据库的JDBC驱动 -->
    <property name="driverClass">
      <value>com.mysql.jdbc.Driver</value>
     </property>
    <!-- 连接数据库所用的URL -->
    <property name="jdbcUrl">
    <value>jdbc:mysql://localhost:3306/lost_and_found?useUnicode=true&amp;characterEncoding=gbk</value>
    </property>
    <!-- 连接数据库的用户名 -->
    <property name="user">
    <value>root</value>
    </property>
    <!-- 连接数据库的密码 -->
    <property name="password">
    <value>root</value>
    </property>
    <!-- 设置数据库连接池的最大连接数 -->
    <property name="maxPoolSize">
    <value>20</value>
    </property>
    <!-- 设置数据库连接池的最小连接数 -->
    <property name="minPoolSize">
    <value>2</value>
    </property>
    <!-- 设置数据库连接池的初始化连接数 -->
    <property name="initialPoolSize">
    <value>2</value>
    </property>
    <!-- 设置数据库连接池的连接的最大空闲时间,单位为秒 -->
    <property name="maxIdleTime">
    <value>20</value>
    </property>
    </bean>
        
        <!-- 定义Hibernate的SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <!-- 依赖注入上面定义的数据源dataSource -->
            <property name="dataSource" ref="dataSource"/>
            <!-- 注册Hibernate的ORM映射文件 -->
    <property name="mappingResources">
    <list>
    <value>com/LostAndFound/ORM/Object.hbm.xml</value>
    <value>com/LostAndFound/ORM/User.hbm.xml</value>
    </list>
    </property>
    <!-- 设置Hibernate的相关属性 -->
            <property name="hibernateProperties">
                <props>
                    <!-- 设置Hibernate的数据库方言 -->
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <!-- 设置Hibernate是否在控制台输出SQL语句,开发调试阶段通常设为true -->
                    <prop key="show_sql">true</prop>
    <!-- 设置Hibernate一个提交批次中的最大SQL语句数 -->
                    <prop key="hibernate.jdbc.batch_size">50</prop>
                </props>
            </property>
    </bean>

    <!-- ==========================原来如此============================== -->


        <!--定义Hibernate的事务管理器HibernateTransactionManager -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <!-- 依赖注入上面定义的sessionFactory -->
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
        
        <!-- 装配HibernateTemplate实例 -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <constructor-arg ref="sessionFactory"/>
    </bean>

    <!-- 装配通用数据库访问类BaseDAOImpl -->    
    <bean id="dao" class="com.LostAndFound.DAO.BaseDAOImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate"/>
    </bean>

    <!-- 以下配置各种beans -->

    </beans>
      

  3.   

    错误说的是你的hibernate配置文件里的user表对应的类是com.eportal.ORM.User
    你的配置文件里是不是有点问题
      

  4.   

    你启动tomcat后  浏览器输入的地址是http://localhost:8080/项目名称/*.jsp么?
      

  5.   

    An association from the table object refers to an unmapped class: com.eportal.ORM.User
    你应该看到了错误了vba
      

  6.   

    Caused by: org.hibernate.MappingException: An association from table object refers to an unmapped class: com.eportal.ORM.Use
    hibernate配置也有问题
      

  7.   

    看是不是没有添加映射 mapping没有找到你的实体类
      

  8.   

    com/LostAndFound/ORM/Object.hbm.xml  这个xml文件配置有问题。。
      

  9.   

    hibernate对象关系映射有问题
    <value>com/LostAndFound/ORM/Object.hbm.xml</value>去掉,
    <value>com/LostAndFound/ORM/User.hbm.xml</value>需要你项目中有User实体类,并且数据库中也有张叫user的表,才能映射,在配置环境的时候可以不用写这些
      

  10.   

    实体类关系映射在Object.hbm.xml 里面出问题了