Java:PostgreSQL Hibernate错误:MySQL的表达式比目标列多

vof42yt1  于 2024-01-05  发布在  Java
关注(0)|答案(1)|浏览(231)

在Hibernate中执行transaction commit命令时,会出现错误“表达式的数量比目标列的数量多”。下面给出的代码是在执行transaction.commit()命令时抛出错误的代码:

  1. @Override
  2. public void saveHearingDetails(HearingDetails hearingDetails)
  3. throws Exception {
  4. Session session = SessionFactoryUtils
  5. .doGetSession(sessionFactory, true);
  6. System.out.println(session);
  7. Transaction transaction = null;
  8. try {
  9. transaction = session.beginTransaction();
  10. session.saveOrUpdate(hearingDetails);
  11. transaction.commit();
  12. session.flush();
  13. } catch (Exception ex) {
  14. ex.printStackTrace();
  15. throw new Exception(ex);
  16. } finally {
  17. SessionFactoryUtils.releaseSession(session, sessionFactory);
  18. }
  19. }

字符串
堆栈跟踪如下:

  1. DEBUG [http-nio-8080-exec-9] SQL.logStatement(111) |
  2. insert
  3. into
  4. public.hearingdetails
  5. (gist_of_hearing, heaing_dt, heaing_dt_with_timestamp, process_updated_date, case_complete, status, fileno1, fileno2, fileno3, hearing_no, dist_code, revdiv_code)
  6. values
  7. (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  8. TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding 'Gist Of Hearing' to parameter: 1
  9. TRACE [http-nio-8080-exec-9] TimestampType.nullSafeSet(151) | binding '2023-12-29 00:00:00' to parameter: 2
  10. TRACE [http-nio-8080-exec-9] TimestampType.nullSafeSet(151) | binding '2023-12-29 13:00:07' to parameter: 3
  11. TRACE [http-nio-8080-exec-9] TimestampType.nullSafeSet(151) | binding '2023-12-29 13:00:07' to parameter: 4
  12. TRACE [http-nio-8080-exec-9] CharacterType.nullSafeSet(144) | binding null to parameter: 5
  13. TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding 'P' to parameter: 6
  14. TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding '5090' to parameter: 7
  15. TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding 'B3' to parameter: 8
  16. TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding '2018' to parameter: 9
  17. TRACE [http-nio-8080-exec-9] IntegerType.nullSafeSet(151) | binding '3' to parameter: 10
  18. TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding '16' to parameter: 11
  19. TRACE [http-nio-8080-exec-9] StringType.nullSafeSet(151) | binding '91' to parameter: 12
  20. WARN [http-nio-8080-exec-9] JDBCExceptionReporter.logExceptions(100) | SQL Error: 0, SQLState: 42601
  21. ERROR [http-nio-8080-exec-9] JDBCExceptionReporter.logExceptions(101) | ERROR: INSERT has more expressions than target columns
  22. Where: PL/pgSQL function hearing_history() line 11 at SQL statement
  23. ERROR [http-nio-8080-exec-9] AbstractFlushingEventListener.performExecutions(324) | Could not synchronize database state with session
  24. org.hibernate.exception.SQLGrammarException: could not insert: [com.nic.edistrict.model.HearingDetails]
  25. at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
  26. at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
  27. at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2295)
  28. at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688)
  29. at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
  30. at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
  31. at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
  32. at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
  33. at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
  34. at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
  35. at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
  36. at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
  37. at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
  38. at com.nic.edistrict.dao.impl.PattaTransferDaoImpl.saveHearingDetails(PattaTransferDaoImpl.java:437)
  39. at com.nic.edistrict.services.impl.PattaInformationManagerImpl.saveHearingDetails(PattaInformationManagerImpl.java:50)
  40. 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个目标列中)。
这里可能有什么问题?请提出解决方案

ar7v8xwq

ar7v8xwq1#

错误实际上是给你更多的信息:
错误[http-nio-8080-exec-9] JDBCExceptionReporter. logarithm(101)|错误:SQL的表达式比目标列多

其中:PL/pgSQL函数hearing_history()在SQL语句第11行

看起来你有一些触发器或过程附加到这个表中的插入,这个过程是无效的。

相关问题