我试图根据给定的条件搜索视图。该视图对于我的应用程序中用户可能想要搜索的多个不同实体有几个字段。Hibernate/Spring HibernateTemplate.findByCriteria(Deatched Criteria dc)在视图上执行sql更新
当我输入我想要搜索的实体的名称时,我在调用.findByCriteria()
之前为名称字段添加了对分离条件的限制。这会导致.findByCriteria()
以我正在查找的名称检索结果列表。
另外,当我查看我的日志时,我可以看到hibernate调用select
陈述。
我现在添加了另一个实体到我的视图,有几个可搜索的字段。当我尝试搜索与此新实体相关的字段时,我的日志中出现异常。
当我通过我的日志,除了看,我可以看到休眠的select
后立即调用select
statment与update
说法(我不是试图更新记录,只需检索它在列表)。
那么为什么在我为新实体调用.findByCriteria()
时,hibernate会调用更新?被执行
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
SQL:
休眠:
select
*
from
(select
this_.SEARCH_ID as SEARCH1_35_0_,
this_.ST_NM as ST24_35_0_
from
SEARCH_RESULT this_
where
this_.LOAN_TYPE=?)
where
rownum <= ?
DEBUG 2012-03-21 11:37:19,332 142195 (http-8181-3:org.springframework.orm.hibernate3.HibernateTemplate): [org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:389)] Eagerly flushing Hibernate session DEBUG 2012-03-21 11:37:19,384 142247 (http-8181-3:org.hibernate.SQL): [org.hibernate.jdbc.util.SQLStatementLogger.logStatement(SQLStatementLogger.java:111)]
update
SEARCH_RESULT
set
ADDR_LINE1=?,
ASSGND_REGION=?,
BASE_DEAL_ID=?,
ST_NM=?
where
SEARCH_ID=?
你可以粘贴SearchResult模型对象的代码吗? – Jeff 2012-03-21 16:13:05
我添加了不可变注解到我的领域类,并解决了我遇到的问题。谢谢杰夫的帮助。 – mandy 2012-03-21 17:24:10