1

我正在尝试调用一个使用 JPA 返回非实体对象的存储过程。这就是我所做的。

StoredProcedureQuery query = entityManager.createStoredProcedureQuery(
            "DepAndTerm", "CalendarsMapping");

query.registerStoredProcedureParameter(0, String.class, ParameterMode.IN);
query.registerStoredProcedureParameter(1, String.class, ParameterMode.IN);
query.registerStoredProcedureParameter(2, String.class, ParameterMode.IN);
query.registerStoredProcedureParameter(3, String.class, ParameterMode.IN);
query.registerStoredProcedureParameter(4, void.class, ParameterMode.REF_CURSOR);

query.setParameter(0, startDate);
query.setParameter(1, endDate);
query.setParameter(2, eventType);
query.setParameter(3, tType);

query.execute();

List<TCalendar> tCalendars = (List<TCalendar>) query.getOutputParameterValue(4);

@SqlResultSetMapping(
  name = "CalendarsMapping",
  classes = {
    @ConstructorResult(
      targetClass = TCalendar.class,
      columns = {
        @ColumnResult(name="BOutDate"),                 
        @ColumnResult(name="CategoryID"),
        @ColumnResult(name="CategoryName")
      }
    )
  }
)

我收到以下异常

java.lang.UnsupportedOperationException: org.hibernate.dialect.Oracle10gDialect does not support resultsets via stored procedures
at org.hibernate.dialect.Dialect.getResultSet(Dialect.java:1645) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.engine.jdbc.cursor.internal.StandardRefCursorSupport.getResultSet(StandardRefCursorSupport.java:125) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.procedure.internal.ProcedureOutputsImpl$ProcedureCurrentReturnState.buildExtendedReturn(ProcedureOutputsImpl.java:106) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.result.internal.OutputsImpl$CurrentReturnState.buildOutput(OutputsImpl.java:209) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.result.internal.OutputsImpl$CurrentReturnState.getOutput(OutputsImpl.java:187) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.result.internal.OutputsImpl.getCurrent(OutputsImpl.java:108) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:234) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]

我不知道我做错了什么。

4

1 回答 1

0

在 Hibernate 5.x 中更新到 12c 方言解决了这个问题。我使用的是休眠 4.2 和 10g 方言。

于 2016-09-02T19:41:42.307 回答