Hibernate注解配置 在Spring的配置文件里写法
<!-- 数据源配置 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- 设置JDBC驱动名称 --> <property name="driverClassName" value="${jdbc.driver}" /> <!-- 设置JDBC连接URL --> <property name="url" value="${jdbc.url}" /> <!-- 设置数据库用户名 --> <property name="username" value="${jdbc.username}" /> <!-- 设置数据库密码 --> <property name="password" value="${jdbc.password}" /> <!-- 设置连接池初始值 --> <property name="initialSize" value="5" /> <!-- 设置连接池最大值 --> <property name="maxActive" value="100" /> <!-- 设置连接池最小空闲值 --> <property name="minIdle" value="20" /> <!-- 设置连接池最大空闲值 --> <property name="maxIdle" value="50" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <!-- 配置Hibernate拦截器,自动填充数据的插入、更新时间 --> <property name="entityInterceptor" ref="entityInterceptor" /> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <value> <!-- 设置数据库方言 --> hibernate.dialect=${hibernate.dialect} <!-- 设置自动创建|更新|验证数据库表结构 --> hibernate.hbm2ddl.auto=update <!-- 输出SQL语句到控制台 --> hibernate.show_sql=${hibernate.show_sql} <!-- 格式化输出到控制台的SQL语句 --> hibernate.format_sql=${hibernate.format_sql} <!-- 是否开启二级缓存 --> hibernate.cache.use_second_level_cache=false <!-- 配置二级缓存产品 --> hibernate.cache.provider_class=org.hibernate.cache.OSCacheProvider <!-- 是否开启查询缓存 --> hibernate.cache.use_query_cache=false <!-- 数据库批量查询数 --> hibernate.jdbc.fetch_size=50 <!-- 数据库批量更新数 --> hibernate.jdbc.batch_size=30 <alue> </property> <property name="annotatedClasses"> <list> <value>net.entity.User<alue> <st> </property> </bean>