由于复杂的原因,我在我的数据库中定义了一个视图,我希望 hibernate 能够读取这个视图,所以我将它映射为一个常规表。这一切似乎在生产中运行良好。
现在我正在运行一个测试,它正在爆炸。我打开了休眠显示 sql 和 sql 注释,这就是我发现的:
Hibernate: /* FROM PostponeDateLimit WHERE postponeDate>=? AND postponeDate <=? AND controlCode = ? ORDER BY postponeDate ASC */ select postponeda0_.REQUEST_DATE as REQUEST1_5_, postponeda0_.COURTLOCATION as COURTLOC2_5_, postponeda0_.ALLOWED as ALLOWED5_, postponeda0_.POSTPONED as POSTPONED5_, postponeda0_.DATECAP as DATECAP5_ from POSTPONE_DATE_VIEW postponeda0_ where postponeda0_.REQUEST_DATE>=? and postponeda0_.REQUEST_DATE<=? and postponeda0_.COURTLOCATION=? order by postponeda0_.REQUEST_DATE ASC
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
Hibernate: /* update com.acs.gs.juror.pojo.PostponeDateLimit */ update POSTPONE_DATE_VIEW set ALLOWED=?, POSTPONED=?, DATECAP=? where REQUEST_DATE=? and COURTLOCATION=?
2012-07-18 16:07:44,503 35529 WARN org.hibernate.util.JDBCExceptionReporter | SQL Error: 4406, SQLState: S1000
2012-07-18 16:07:44,503 35529 ERROR org.hibernate.util.JDBCExceptionReporter | Update or insert of view or function 'EJUROR_POSTPONE_DATE_VIEW' failed because it contains a derived or constant field.
所以更新视图会导致异常。
只有第一个查询是由我发起的。由于某些奇怪的原因,这些更新似乎是由休眠创建的。我一生都无法弄清楚为什么以及为什么它在我的本地测试盒上而不是在我们的现场盒上这样做。
这是我的休眠映射:
<class name="com.pojo.PostponeDateLimit" table="POSTPONE_DATE_VIEW">
<composite-id class="com.acs.gs.juror.pojo.PostponeDateLimitKey" mapped="true">
<key-property name="postponeDate" type="calendar" column="REQUEST_DATE"/>
<key-property name="controlCode" column="COURTLOCATION"/>
</composite-id>
<property name="maxCount" column="ALLOWED"/>
<property name="postponedCount" column="POSTPONED"/>
<property name="dateCap" column="DATECAP"/>
</class>
有没有人有洞察力?