org.hibernate.HibernateException: Errors in named queries问题

本文介绍了解决Hibernate框架中出现的NamedQueries错误的方法,包括升级Hibernate版本、调整配置文件中的属性设置以及正确指定映射文件的位置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


org.hibernate.HibernateException: Errors in named queries问题解决方案:

1、从hibernate版本升级入手
2、配置的org.springframework.orm.hibernate3.LocalSessionFactoryBean中的hibernateProperties入手:
<property name="hibernateProperties">
			<props>
				<!--
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				-->
				<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
				<prop key="hibernate.cache.provider">org.hibernate.cache.EhCacheProvider</prop>
				<prop key="hibernate.cache.use_query_cache">true</prop>
				<prop key="hibernate.cache.use_second_level_cache">true</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
				<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
				<prop key="hibernate.connection.setBigStringTryClob">true</prop>
				<prop key="connection.autoReconnect">true</prop>
				<prop key="connection.autoReconnectForPools">true</prop>
				<prop key="connection.is-connection-validation-required">true</prop>
				<!--
				<prop key="hibernate.hbm2ddl.auto">validate | update | create | create-drop</prop>
				<prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
				<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
				<prop key="hibernate.jdbc.batch_size">50</prop>
				<prop key="hibernate.jdbc.fetch_Size">100</prop>
				-->
			</props>
		</property>
3、从mappingLocations入手:
<property name="mappingLocations">
			<list>
				<value>classpath*:/com/businessmatrix/**/entity/dbo/*.hbm.xml</value>
				<value>classpath*:/com/businessmatrix/auth/entity/dbo/nameQuery/NQ-auth.xml</value>
			</list>
		</property>
总的配置:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="lobHandler" ref="oracleLobHandle"/> 
		<property name="dataSource" ref="dataSource" />
		<!--  <property name="mappingDirectoryLocations">-->
		<!-- <property name="mappingLocations">
			<list>
				<value>classpath*:/com/businessmatrix/**/entity/dbo/*.hbm.xml</value>
			</list>
		</property>
		<property name="mappingResources">
			<list>
				<value>com/businessmatrix/auth/entity/dbo/nameQuery/NQ-auth.xml</value>
			</list>
		</property> -->
		<property name="mappingLocations">
			<list>
				<value>classpath*:/com/businessmatrix/**/entity/dbo/*.hbm.xml</value>
				<value>classpath*:/com/businessmatrix/auth/entity/dbo/nameQuery/NQ-auth.xml</value>
			</list>
		</property>
		<!-- <property name="mappingJarLocations">
			<list>
				<value>WEB-INF/lib/ips-auth20160309.jar</value>
			</list>
		</property> -->
		<property name="hibernateProperties">
			<props>
				<!--
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				-->
				<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
				<prop key="hibernate.cache.provider">org.hibernate.cache.EhCacheProvider</prop>
				<prop key="hibernate.cache.use_query_cache">true</prop>
				<prop key="hibernate.cache.use_second_level_cache">true</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
				<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
				<prop key="hibernate.connection.setBigStringTryClob">true</prop>
				<prop key="connection.autoReconnect">true</prop>
				<prop key="connection.autoReconnectForPools">true</prop>
				<prop key="connection.is-connection-validation-required">true</prop>
				<!--
				<prop key="hibernate.hbm2ddl.auto">validate | update | create | create-drop</prop>
				<prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
				<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
				<prop key="hibernate.jdbc.batch_size">50</prop>
				<prop key="hibernate.jdbc.fetch_Size">100</prop>
				-->
			</props>
		</property>
	</bean>

	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    
	<tx:annotation-driven transaction-manager="transactionManager" />
	<!--
	<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
	-->
    
	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值