標籤:hibernate註解hql 報錯
@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.MySQLDialecthibernate.show_sql=truehibernate.format_sql=truehibernate.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
hibernate註解HQL 報錯