@Entity(name="icertInfo") HQL 查询的时候 需要写Entry 的name值,要不然会报错 iCertInfo is not mapped
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 用户名 --> <property name="user" value="${db_username}" /> <!-- 用户密码 --> <property name="password" value="${db_password}" /> <property name="driverClass" value="${db_driver_class}" /> <property name="jdbcUrl" value="${db_url}" /> <!--连接池中保留的最大连接数。默认值: 15 --> <property name="maxPoolSize" value="20" /> <!-- 连接池中保留的最小连接数,默认为:3 --> <property name="minPoolSize" value="5" /> <!-- 初始化连接池中的连接数,取值应在minPoolSize与maxPoolSize之间,默认为3 --> <property name="initialPoolSize" value="2" /> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。默认值: 3 --> <property name="acquireIncrement" value="2" /> <!--定义在从数据库获取新连接失败后重复尝试的次数。默认值: 30 ;小于等于0表示无限次 --> <property name="acquireRetryAttempts" value="0" /> <!--重新尝试的时间间隔,默认为:1000毫秒 --> <property name="acquireRetryDelay" value="1000" /> </bean> <!-- 获取hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hibernate.format_sql=true hibernate.hbm2ddl.auto=update </value> </property> <property name="packagesToScan"> <list> <value>com.itrus.business.model</value> </list> </property> </bean>
packagesToScan ,配置错误 HQL 也会报错
package com.itrus.business.properties; import java.util.HashMap; import java.util.Map; import java.util.Properties; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; public class ProInfo extends PropertyPlaceholderConfigurer { private static Map<String, Object> ctxPropertiesMap; @Override protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)throws BeansException { super.processProperties(beanFactory, props); ctxPropertiesMap = new HashMap<String, Object>(); for (Object key : props.keySet()) { String keyStr = key.toString(); String value = props.getProperty(keyStr); ctxPropertiesMap.put(keyStr, value); } } public static Object getContextProperty(String name) { return ctxPropertiesMap.get(name); } }
URL=
#AccountHash=
AccountHash=
Password=password
fapiaotong=
certpath=E\://test.cer
db_username=root
#db_password=
db_password=
db_driver_class=com.mysql.jdbc.Driver
#db_url=jdbc\:mysql\://\:3306/hibernate?useUnicode\=true&characterEncoding\=UTF-8
db_url=jdbc\:mysql\://localhost\:3306/hibernate?useUnicode\=true&characterEncoding\=UTF-8
<!-- 读取配置文件 --> <bean id="proinfo" class="com.itrus.business.properties.ProInfo"> <property name="locations"> <list> <value>classpath:info.properties</value> </list> </property> </bean>
不配置包扫描 查询需要写全名 com.itrus.business.model.ICertInfo
时间: 2024-10-06 00:10:40