在Hibernate中执行transaction commit命令时,会出现错误“表达式的数量比目标列的数量多”。下面给出的代码是在执行transaction.commit()命令时抛出错误的代码:
@Override
public void saveHearingDetails(HearingDetails hearingDetails)
throws Exception {
Session session = SessionFactoryUtils
.doGetSession(sessionFactory, true);
System.out.println(session);
Transaction transaction = null;
try {
transaction = session.beginTransaction();
session.saveOrUpdate(hearingDetails);
transaction.commit();
session.flush();
} catch (Exception ex) {
ex.printStackTrace();
throw new Exception(ex);
} finally {
SessionFactoryUtils.releaseSession(session, sessionFactory);
}
}
字符串
堆栈跟踪如下:
DEBUG [http-nio-8080-exec-9] SQL.logStatement(111) |
insert
into
public.hearingdetails
(gist_of_hearing, heaing_dt, heaing_dt_with_timestamp, process_updated_date, case_complete, status, fileno1, fileno2, fileno3, hearing_no, dist_code, revdiv_code)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding 'Gist Of Hearing' to parameter: 1
TRACE [http-nio-8080-exec-9] TimestampType.nullSafeSet(151) | binding '2023-12-29 00:00:00' to parameter: 2
TRACE [http-nio-8080-exec-9] TimestampType.nullSafeSet(151) | binding '2023-12-29 13:00:07' to parameter: 3
TRACE [http-nio-8080-exec-9] TimestampType.nullSafeSet(151) | binding '2023-12-29 13:00:07' to parameter: 4
TRACE [http-nio-8080-exec-9] CharacterType.nullSafeSet(144) | binding null to parameter: 5
TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding 'P' to parameter: 6
TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding '5090' to parameter: 7
TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding 'B3' to parameter: 8
TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding '2018' to parameter: 9
TRACE [http-nio-8080-exec-9] IntegerType.nullSafeSet(151) | binding '3' to parameter: 10
TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding '16' to parameter: 11
TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding '91' to parameter: 12
WARN [http-nio-8080-exec-9] JDBCExceptionReporter.logExceptions(100) | SQL Error: 0, SQLState: 42601
ERROR [http-nio-8080-exec-9] JDBCExceptionReporter.logExceptions(101) | ERROR: INSERT has more expressions than target columns
Where: PL/pgSQL function hearing_history() line 11 at SQL statement
ERROR [http-nio-8080-exec-9] AbstractFlushingEventListener.performExecutions(324) | Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [com.nic.edistrict.model.HearingDetails]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2295)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at com.nic.edistrict.dao.impl.PattaTransferDaoImpl.saveHearingDetails(PattaTransferDaoImpl.java:437)
at com.nic.edistrict.services.impl.PattaInformationManagerImpl.saveHearingDetails(PattaInformationManagerImpl.java:50)
at com.nic.edistrict.action.state.PattainformationAction.upnextHeraingDt(PattainformationAction.java:940)
型
但是命令中的值的数量与目标列的数量相同,如“insertintopublic.hearingdetails”中所示(gist_of_hearing、heing_dt、heing_dt_with_timestamp、process_updated_date、case_complete、status、fileno1、fileno2、fileno3、hearing_no、dist_code、revdiv_code)值(?,?)”命令在Hibernate的日志中显示(12个值插入到12个目标列中)。
这里可能有什么问题?请提出解决方案
1条答案
按热度按时间ar7v8xwq1#
错误实际上是给你更多的信息:
错误[http-nio-8080-exec-9] JDBCExceptionReporter. logarithm(101)|错误:SQL的表达式比目标列多
其中:PL/pgSQL函数hearing_history()在SQL语句第11行
看起来你有一些触发器或过程附加到这个表中的插入,这个过程是无效的。