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.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-08-05 08:55:40

hibernate注解HQL 报错的相关文章

spring+hibernate整合:报错org.hibernate.HibernateException: No Session found for current thread

spring+hibernate整合:报错信息如下 org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106) at org.hibernate.internal.SessionFactoryImpl.getC

使用idea引入注解@SpringBootApplication报错Cannot resolve symbol &#39;SpringBootApplication&#39;

我在使用idea时,在类上使用注解@SpringBootApplication,但是一直报错. Cannot resolve symbol 'SpringBootApplication' 网络上有很多种方法,比如有的方法是把repository删除,然后重新maven project: 有的是因为目录spring-boot-autoconfigure中很多个release版本,把所有的版本都删除,然后重新install.如下所示: 有的办法是在Intellij idea下 file->Inval

idea操作 clone项目、 import项目所有注解全部报错

操作:从现有的git上边clone项目,前提是开发工具,开发环境都一样错误类型:所有的注解全部报错 原因: 是选择了Create from existing source 一路Next下去,Maven项目导入成功 Import from external model:选项允许你导入一个已经存在的固定model的项目.例如Eclipse和Maven等.IDEA会根据你选择的model自动转换项目文件,换句话说就是把项目成功从原来的平台迁移到IDEA. Create from existing so

org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread spring集成Hibernate sessionfactory.getcurrentSession报错

sessionFactory.getCurrentSession()是要基于事务的,解决方法为在javaconfig配置类使用@EnableTransactionManagement注解  并且配置transactionManager bean. 在报错方法中使用@Transactional注解 原文地址:https://www.cnblogs.com/alexmason236/p/9767091.html

Java中@Controller注解和@ResponseBody注解,报错找不到template

报错信息:org.thymeleaf.exceptions.TemplateInputException: Error resolving template "xxxxx", template might not exist or might not be accessible by any of the configured Template Resolvers 运行提示找不到模板时, 在controller类上加注解@Controller 和@RestController都可以在前

Hibernate分页查询报错

不知道什么原因,就是这里报错的 原文地址:https://www.cnblogs.com/feifeicui/p/8735182.html

shiro + struts2 在action 中使用 shiro 注解 @requiresPermissions 报错: 方法找不到,类初始失败

06:36:34,405 ERROR http-8084-2 dispatcher.Dispatcher:38 - Exception occurred during processing request: $Proxy15.user_() java.lang.NoSuchMethodException: $Proxy*.user_() at java.lang.Class.getMethod(Class.java:1605) at org.apache.struts2.interceptor.

解决非controller使用@Autowired注解注入报错为java.lang.NullPointerException问题

在SpringMVC框架中,我们经常要使用@Autowired注解注入Service或者Mapper接口,我们也知道,在controller层中注入service接口,在service层中注入其它的service接口或者mapper接口都是可以的,但是如果我们要在我们自己封装的Utils工具类中或者非controller普通类中使用@Autowired注解注入Service或者Mapper接口,直接注入是不可能的,因为Utils使用了静态的方法,我们是无法直接使用非静态接口的,当我们遇到这样的问

hibernate报错:no currentsessioncontext configured!

使用hibernate框架时候报错:no currentsessioncontext configured! 这个错误是当我们使用getCurrentSession();时候引起的,原因是currentSession配置错误,与事务有关,当我们使用currentSession的时候需要在hibernate.cfg.xml中进行如下事务配置: 1.如果是本地事务: <property name="hibernate.current_session_context_class">