问题描述:
1、项目为java-web项目,hql查询代码写在业务逻辑类中,
2、看日志中,hibernate发出查询语句之后,就会出现x条update语句的日志,而x的值与查询结果数据的行数一致。
3、在update语句出现后,hibernate提交事务的相关类中出异常啦“数据长度10,限制的长度为8,无法update”.
问题原因:
在该类的hbm.xml文件中,发现某一属性的配置,与oracle的关键字date冲突
<property
name="Date"
column="TXNDATE"
type="string"
not-null="true"
length="8"
/>
将类的属性名字修改即可。
问题分析:
1、即使是hql查询的List对象,也是hibernate的持久态对象。
事务管理对象与事务代理对象
<bean id="transactionManagerCtl"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactoryCtl" />
</property>
</bean>
<bean id="transactionInterceptorCtl"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManagerCtl" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
业务逻辑类与业务逻辑类的代理类
<bean id="ADMZXGBOTarget" class="buss.console.db.service.impl.AdmZxgBO_Impl"
singleton="false">
</bean>
<bean id="ADMZXGBO" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>buss.console.db.service.iface.I_AdmZxgBO</value>
</property>
<property name="target">
<ref local="ADMZXGBOTarget" />
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptorCtl</value>
</list>
</property>
</bean>
2、hibernate在提交的事务的时候,会将当前session中持久态对象与数据库中数据相互比较,如果不同就会出现update语句。
3、hbm.xml中的名字为date的属性会影响到hql转化为正常的sql语句,从而使加载上来的list中对象的date属性值与实际数据库中表的date字段值不一致。